private void cmd_SaveDoc(System.Object sender, EventArgs e)
        {
            if (m_MapControl.CheckMxFile(m_MapControl.DocumentFilename))
            {
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_MapControl.DocumentFilename, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_MapControl.DocumentFilename))
                {
                    MessageBox.Show("地图为只读!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Example #2
0
        /// <summary>
        /// 地图文档编辑过后进行保存
        /// </summary>
        private void Save_Click(object sender, EventArgs e)
        {
            //获取pMapDocument对象
            IMxdContents pMxdC;

            pMxdC = axMapControl1.Map as IMxdContents;
            IMapDocument pMapDocument = new MapDocumentClass();

            pMapDocument.Open(axMapControl1.DocumentFilename, "");
            IActiveView pActiveView = axMapControl1.Map as IActiveView;

            pMapDocument.ReplaceContents(pMxdC);
            //判断pMapDocument是否为空
            if (pMapDocument == null)
            {
                return;
            }
            //检查地图文档是否是只读
            if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
            {
                MessageBox.Show("本地图文档是只读的,不能保存!");
                return;
            }

            //根据相对的路径保存地图文档
            pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
        }
Example #3
0
 private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (axMapControl1.DocumentMap == null)
     {
         MessageBox.Show("地图文档不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         try
         {
             IMapDocument pMapDocument = new MapDocumentClass();
             string       saveFileName = axMapControl1.DocumentFilename;
             IMxdContents pMxdcontents = axMapControl1.Map as IMxdContents;
             pMapDocument.New(saveFileName);
             pMapDocument.ReplaceContents(pMxdcontents);
             if (pMapDocument.get_IsReadOnly(saveFileName))
             {
                 MessageBox.Show("本地图文档只读的,不能保存!");
             }
             else
             {
                 pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                 MessageBox.Show("保存地图文档成功!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Example #4
0
        /// <summary>
        /// 保存mxd文档
        /// mapControl为地图控件的名称
        /// 日期2013-12-13
        /// lntu_GISer1
        /// </summary>
        public void SaveMxdFile(AxMapControl mapControl)
        {
            IMxdContents pMxdC;

            pMxdC = mapControl.ActiveView.FocusMap as IMxdContents;
            IMapDocument pMapDocument = new MapDocumentClass();

            if (mapControl.DocumentFilename != null)
            {
                pMapDocument.Open(mapControl.DocumentFilename, "");
                pMapDocument.ReplaceContents(pMxdC);
                if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename))
                {
                    MessageBox.Show("当前地图文档为只读文档!");
                    return;
                }
                try
                {
                    pMapDocument.Save(true, true);
                    MessageBox.Show("地图文档保存成功!");
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }

            //用当前的文件路径设置保存文件
        }
Example #5
0
        private void menuSaveDoc_Click(object sender, EventArgs e)
        {
            //execute Save Document command
            if (m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Example #6
0
        private void SaveDocument()
        {
            try
            {
                if (mapControl.CheckMxFile(m_mapDocumentName))
                {
                    //使用MapDocument对象保存文件
                    IMapDocument mapDocument = new MapDocumentClass();
                    mapDocument.Open(m_mapDocumentName, string.Empty);

                    //判断文件是不是只读的
                    if (mapDocument.get_IsReadOnly(m_mapDocumentName))
                    {
                        MessageBox.Show("地图文件是只读的!");
                        mapDocument.Close();
                        return;
                    }
                    //替换已有的文件
                    mapDocument.ReplaceContents((IMxdContents)mapControl.Map);
                    //保存文件
                    mapDocument.Save(mapDocument.UsesRelativePaths, false);
                    mapDocument.Close();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
 //保存地图文档
 public static void SaveMapDocument(ESRI.ArcGIS.Controls.AxMapControl axMapControl)
 {
     if (axMapControl == null)
     {
         return;
     }
     string m_mapDocumentName = axMapControl.DocumentFilename;
     if (axMapControl.CheckMxFile(m_mapDocumentName))
     {
         //新建地图文档接口
         IMapDocument mapDoc = new MapDocumentClass();
         mapDoc.Open(m_mapDocumentName, string.Empty);
         //确定文档非只读文件
         if (mapDoc.get_IsReadOnly(m_mapDocumentName))
         {
             MessageBox.Show("Map document is read only!");
             mapDoc.Close();
             return;
         }
         //用当前地图替换文档内容
         mapDoc.ReplaceContents((IMxdContents)axMapControl.Map);
         //保存文档
         mapDoc.Save(mapDoc.UsesRelativePaths, false);
         //关闭文档
         mapDoc.Close();
     }
 }
Example #8
0
        //保存地图文档
        public static void SaveMapDocument(ESRI.ArcGIS.Controls.AxMapControl axMapControl)
        {
            if (axMapControl == null)
            {
                return;
            }
            string m_mapDocumentName = axMapControl.DocumentFilename;

            if (axMapControl.CheckMxFile(m_mapDocumentName))
            {
                //新建地图文档接口
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);
                //确定文档非只读文件
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }
                //用当前地图替换文档内容
                mapDoc.ReplaceContents((IMxdContents)axMapControl.Map);
                //保存文档
                mapDoc.Save(mapDoc.UsesRelativePaths, false);
                //关闭文档
                mapDoc.Close();
            }
        }
Example #9
0
        private void BtnSaveMXD_Click(object sender, EventArgs e)
        {
            //make sure that the current MapDoc is valid first
            if (m_documentFileName != string.Empty && m_mapControl.CheckMxFile(m_documentFileName))
            {
                //create a new instance of a MapDocument class
                IMapDocument mapDoc = new MapDocumentClass();
                //Open the current document into the MapDocument
                mapDoc.Open(m_documentFileName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_documentFileName))
                {
                    MessageBox.Show("سند فقط خواندنی است");
                    mapDoc.Close();
                    return;
                }

                //Replace the map with the one of the PageLayout
                mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);

                //save the document
                mapDoc.Save(mapDoc.UsesRelativePaths, false);
                mapDoc.Close();
            }
        }
Example #10
0
                private void Save_Click(object sender, EventArgs e)
               
        {
                        //execute Save Document command
                            if (m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                            {
                                    //create a new instance of a MapDocument
                                    IMapDocument mapDoc = new MapDocumentClass();
                                    mapDoc.Open(m_mapDocumentName, string.Empty);

                                    //Make sure that the MapDocument is not readonly
                                        if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                    {
                                        {
                                                MessageBox.Show("Map document is read only!");

                                                mapDoc.Close();

                                                return;

                                           
                        }
                    }

                               
                }
            }

                   
        }
Example #11
0
        private void barButtonItem25_ItemClick(object sender, ItemClickEventArgs e)
        {
            string m_currentMapDocument = axMapControl1.DocumentFilename;

            //execute Save Document command

            if (axMapControl1.CheckMxFile(m_currentMapDocument))

            {
                //create a new instance of a MapDocument

                IMapDocument mapDoc = new MapDocumentClass();

                mapDoc.Open(m_currentMapDocument, string.Empty);



                //Make sure that the MapDocument is not readonly

                if (mapDoc.get_IsReadOnly(m_currentMapDocument))

                {
                    MessageBox.Show("Map document is read only!");

                    mapDoc.Close();

                    return;
                }



                //Replace its contents with the current map

                mapDoc.ReplaceContents((IMxdContents)axMapControl1.Map);



                //save the MapDocument in order to persist it

                mapDoc.Save(mapDoc.UsesRelativePaths, false);



                //close the MapDocument

                mapDoc.Close();



                MessageBox.Show("保存地图文档成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }

            else

            {
                MessageBox.Show(m_currentMapDocument + "不是有效的地图文档!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #12
0
        public void OnClick()
        {
            //// 首先确认当前地图文档是否有效  
            //if (null != m_pageLayoutControl.DocumentFilename && m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename))  
            //{  
            //// 创建一个新的地图文档实例  
            //IMapDocument mapDoc = new MapDocumentClass();  // 打开当前地图文档  
            //mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty);  // 用 PageLayout 中的文档替换当前文档中的 PageLayout 部分  
            //mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);  // 保存地图文档  
            //mapDoc.Save(mapDoc.UsesRelativePaths, false);  
            //mapDoc.Close();  

            //m_mapDocument = this.hk.Document;
            //if (m_mapDocument.get_IsReadOnly(m_mapDocument.DocumentFilename))
            //{
            //    MessageBox.Show("This map document is read only!");
            //    return;
            //}
            //m_mapDocument.Save(m_mapDocument.UsesRelativePaths, true);
            //MessageBox.Show("Changes saved successfully!");

            //execute Save Document command
            //m_mapDocumentName = m_mapControl.DocumentFilename;
            if (m_mapControl.DocumentFilename != null && m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                //m_mapControl.CheckMxFile(m_mapDocumentName);
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
            else
            {
                cmd = new ControlsSaveAsDocCommandClass();
                cmd.OnCreate(this.m_mapControl);
                cmd.OnClick();
            }
        }
Example #13
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (axMapControl1.DocumentMap == null)
     {
         MessageBox.Show("地图文档不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         try
         {
             IMapDocument pMapDocument = new MapDocumentClass();
             string       saveFileName = axMapControl1.DocumentFilename;
             if (saveFileName != "" && axMapControl1.CheckMxFile(saveFileName))
             {
                 if (pMapDocument.get_IsReadOnly(saveFileName))
                 {
                     MessageBox.Show("本地图文档只读的,不能保存!");
                     pMapDocument.Close();
                     return;
                 }
                 else
                 {
                     SaveFileDialog saveFileDialog = new SaveFileDialog();
                     saveFileDialog.Title  = "保存文档";
                     saveFileDialog.Filter = "MXD文档(*.mxd)|*.mxd";
                     string fileName = System.IO.Path.GetFileName(saveFileName);
                     saveFileDialog.FileName = fileName;
                     if (saveFileDialog.ShowDialog() == DialogResult.OK)
                     {
                         saveFileName = saveFileDialog.FileName;
                         pMapDocument.New(saveFileName);
                         pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents);
                         pMapDocument.Save(true, true);
                         pMapDocument.Close();
                         MessageBox.Show("保存成功!");
                     }
                     else
                     {
                         pMapDocument.Close();
                         return;
                     }
                 }
             }
             else
             {
                 MessageBox.Show("无法保存!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Example #14
0
        public static void save_doc()
        {
            try
            {
                string       filename     = mainForm.mainform.mainMapControl.DocumentFilename;
                IMapDocument pMapDocument = new MapDocumentClass();
                if (filename != null && mainForm.mainform.mainMapControl.CheckMxFile(filename))
                {
                    if (pMapDocument.get_IsReadOnly(filename))
                    {//地图文档只读
                        MessageBox.Show("该地图文档是只读的,无保存权限!", "信息提示", MessageBoxButtons.OK);
                        pMapDocument.Close();
                        return;
                    }
                }
                else
                {//地图文档为空,创建地图文档
                    //实例化SaveFileDialog
                    SaveFileDialog pSaveFileDialog = new SaveFileDialog
                    {
                        Title            = "请选择保存路径",
                        OverwritePrompt  = true,
                        RestoreDirectory = true,
                        Filter           = "ArcMap文档(*.mxd)|*.mxd"
                    };

                    if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        filename = pSaveFileDialog.FileName;
                        return;
                    }
                    else
                    {
                        return;
                    }
                }

                //统一保存地图文档
                pMapDocument.New(filename);
                pMapDocument.ReplaceContents(mainForm.mainform.mainMapControl.Map as IMxdContents);
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                pMapDocument.Close();
                MessageBox.Show("保存地图文档成功!", "信息提示", MessageBoxButtons.OK);
            }
            catch (Exception exc)
            {
                MessageBox.Show("地图文档保存失败!" + exc.Message, "信息提示", MessageBoxButtons.OK);
            }
        }
Example #15
0
        public static void SaveDocument()
        {
            try
            {
                string       sMxdFileName = Form1.form1.axMapControl1.DocumentFilename;
                IMapDocument pMapDocument = new MapDocumentClass();
                if (sMxdFileName != null && Form1.form1.axMapControl1.CheckMxFile(sMxdFileName))
                {
                    if (pMapDocument.get_IsReadOnly(sMxdFileName))
                    {
                        MessageBox.Show("本地图文档是只读的,不能保存!");
                        pMapDocument.Close();
                        return;
                    }
                }
                else
                {
                    SaveFileDialog pSaveFileDialog = new SaveFileDialog
                    {
                        Title            = "请选择保存路径",
                        OverwritePrompt  = true,
                        Filter           = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt",
                        RestoreDirectory = true
                    };
                    if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        sMxdFileName = pSaveFileDialog.FileName;
                    }
                    else
                    {
                        return;
                    }
                }

                pMapDocument.New(sMxdFileName);
                pMapDocument.ReplaceContents(Form1.form1.axMapControl1.Map as IMxdContents);
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                pMapDocument.Close();
                MessageBox.Show("保存地图文档成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //ICommand command = new ControlsSaveAsDocCommandClass();
            //command.OnCreate(Form1.form1.axMapControl1.Object);
            //command.OnClick();
        }
Example #16
0
 /// <summary>
 /// 保存地图文档
 /// </summary>
 /// <param name="m_FilePath"></param>
 /// <param name="m_SaveMap"></param>
 /// <returns></returns>
 public void SaveMap(string m_FilePath, IMap m_SaveMap)
 {
     try
     {
         IMapDocument pMapDoc = new MapDocumentClass();
         IMxdContents pMxdC   = m_SaveMap as IMxdContents;
         pMapDoc.New(m_FilePath);
         pMapDoc.ReplaceContents(pMxdC);
         if (pMapDoc.get_IsReadOnly(pMapDoc.DocumentFilename) == true)
         {
             MessageBox.Show("本地图文档是只读的,不能保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         pMapDoc.Save(pMapDoc.UsesRelativePaths, true);
     }
     catch (Exception ex)
     {
     }
 }
Example #17
0
        //地图文档另存为;
        private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //保存地图文档.mxd
            try
            {
                string       smxdfilename = axMapControl1.DocumentFilename;
                IMapDocument pmapdocument = new MapDocumentClass();
                if (smxdfilename != null && axMapControl1.CheckMxFile(smxdfilename))
                {
                    if (pmapdocument.get_IsReadOnly(smxdfilename))
                    {
                        MessageBox.Show("本地图为只读文档,不能修改保存!");
                        pmapdocument.Close();
                        return;
                    }
                }
                else
                {
                    saveFileDialog1.Title            = "选择保存路径";
                    saveFileDialog1.OverwritePrompt  = true;
                    saveFileDialog1.Filter           = "ArcMap文档(*.mxd)|*.mxd";
                    saveFileDialog1.RestoreDirectory = true;

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        smxdfilename = saveFileDialog1.FileName;
                    }
                    else
                    {
                        return;
                    }
                }
                pmapdocument.ReplaceContents(axMapControl1.Map as IMxdContents);
                pmapdocument.New(smxdfilename);
                pmapdocument.Save(true, true);
                pmapdocument.Close();
                MessageBox.Show("地图保存成功!");
            }
            catch (Exception arr)
            {
                MessageBox.Show("错误:" + arr.Message, "提示", MessageBoxButtons.OK);
            }
        }
        /// <summary>
        /// 地图文档保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveMap_Click(object sender, EventArgs e)
        {
            try
            {
                string       sMxdFileName = MainMapControl.DocumentFilename;
                IMapDocument pMapDocument = new MapDocumentClass();
                if (sMxdFileName != null && MainMapControl.CheckMxFile(sMxdFileName))
                {
                    if (pMapDocument.get_IsReadOnly(sMxdFileName))
                    {
                        MessageBox.Show("本地图文档是只读,不能保存!");
                        pMapDocument.Close();
                        return;
                    }
                    else
                    {
                        SaveFileDialog pSaveFileDialog = new SaveFileDialog();
                        pSaveFileDialog.Title            = "请选择保存路径";
                        pSaveFileDialog.OverwritePrompt  = true;
                        pSaveFileDialog.Filter           = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt";
                        pSaveFileDialog.RestoreDirectory = true;
                        if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            sMxdFileName = pSaveFileDialog.FileName;
                        }
                        else
                        {
                            return;
                        }
                    }

                    pMapDocument.New(sMxdFileName);
                    pMapDocument.ReplaceContents(MainMapControl.Map as IMxdContents);
                    pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                    pMapDocument.Close();
                    MessageBox.Show("保存地图文档成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //保存地图文档
        private void barButtonItem26_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                string       sMxdFileName = Variable.pMapFrm.mainMapControl.DocumentFilename;
                IMapDocument pMapDocument = new MapDocumentClass();
                if (sMxdFileName != null && Variable.pMapFrm.mainMapControl.CheckMxFile(sMxdFileName))
                {
                    if (pMapDocument.get_IsReadOnly(sMxdFileName))
                    {
                        MessageBox.Show("本地图文档是只读的,不能保存!");
                        pMapDocument.Close();
                        return;
                    }
                }
                else
                {
                    SaveFileDialog pSaveFileDialog = new SaveFileDialog();
                    pSaveFileDialog.Title            = "请选择保存路径";
                    pSaveFileDialog.OverwritePrompt  = true;
                    pSaveFileDialog.Filter           = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt";
                    pSaveFileDialog.RestoreDirectory = true;
                    if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        sMxdFileName = pSaveFileDialog.FileName;
                    }
                    else
                    {
                        return;
                    }
                }

                pMapDocument.New(sMxdFileName);
                pMapDocument.ReplaceContents(Variable.pMapFrm.mainMapControl.Map as IMxdContents);
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                pMapDocument.Close();
                MessageBox.Show("保存地图文档成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "/n" + ex.ToString(), "异常");
            }
        }
Example #20
0
 private void SaveItem_Click(object sender, EventArgs e)
 {
     try
     {
         string       mxdpath = this.axMapcontrol.DocumentFilename;
         IMapDocument mapDoc  = new MapDocumentClass();
         if (!string.IsNullOrEmpty(mxdpath) && this.axMapcontrol.CheckMxFile(mxdpath))
         {
             if (mapDoc.get_IsReadOnly(mxdpath))
             {
                 MessageBox.Show("该文档为只读不能保存");
                 return;
             }
         }
         else
         {
             //当没有默认路径时
             SaveFileDialog dlg = new SaveFileDialog();
             dlg.AddExtension     = true;
             dlg.Filter           = "地图文档(*.mxd)|*.mxd";
             dlg.RestoreDirectory = true;
             dlg.OverwritePrompt  = true;
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 mxdpath = dlg.FileName;
             }
             else
             {
                 return;
             }
         }
         mapDoc.New(mxdpath);
         mapDoc.ReplaceContents(this.axMapcontrol.Map as IMxdContents);
         mapDoc.Save(mapDoc.UsesRelativePaths, true);
         mapDoc.Close();
         MessageBox.Show("保存地图文档成功");
     }
     catch (Exception ex)
     {
         MessageBox.Show("保存失败" + ex.Message);
     }
 }
Example #21
0
        //保存
        public static void SaveDoc(AxMapControl mapControl, AxPageLayoutControl pageLayoutControl = null)
        {
            //判断文档是否为只读文档
            IMapDocument pMapDocument = new MapDocumentClass();

            if (mapControl.Map.LayerCount != 0 && mapControl.DocumentFilename != null)
            {
                pMapDocument.Open(mapControl.DocumentFilename);
                if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename))
                {
                    MessageBox.Show("此地图文档为只读文档", "信息提示");
                    return;
                }
                //用相对路径保存地图文档
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                MessageBox.Show("保存成功!", "信息提示");
            }
            else
            {
                OperateFile.SaveDocAs(mapControl, pageLayoutControl);
            }
        }
Example #22
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IPageLayoutControl3 pPageLayoutControl = null;

            if (m_hookHelper.Hook is IToolbarControl)
            {
                pPageLayoutControl = (IPageLayoutControl3)((IToolbarControl)m_hookHelper.Hook).Buddy;
            }
            //In case the container is MapControl
            else if (m_hookHelper.Hook is IPageLayoutControl3)
            {
                pPageLayoutControl = (IPageLayoutControl3)m_hookHelper.Hook;
            }
            else
            {
                MessageBox.Show("当前界面必须是PageLayoutControl界面!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                string strDocName = pPageLayoutControl.DocumentFilename;
                if (strDocName != null)
                {
                    if (pPageLayoutControl.CheckMxFile(strDocName))
                    {
                        //create a new instance of a MapDocument
                        IMapDocument mapDoc = new MapDocumentClass();
                        mapDoc.Open(strDocName, string.Empty);

                        //Make sure that the MapDocument is not readonly
                        if (mapDoc.get_IsReadOnly(strDocName))
                        {
                            MessageBox.Show("Map document is read only!");
                            mapDoc.Close();
                            return;
                        }

                        //Replace its contents with the current map
                        mapDoc.ReplaceContents((IMxdContents)pPageLayoutControl.PageLayout);

                        //save the MapDocument in order to persist it
                        mapDoc.Save(true, true);

                        //close the MapDocument
                        mapDoc.Close();
                    }
                }
                else
                {
                    IMapDocument   mDoc    = new MapDocumentClass(); //地图文档对象
                    SaveFileDialog dlgFile = new SaveFileDialog();   //以对话框选择文档路径
                    string         sFilePath;
                    dlgFile.Title  = "另存地图文档";
                    dlgFile.Filter = "Map Documents(*.mxd)|*.mxd";
                    if (dlgFile.ShowDialog() == DialogResult.OK)
                    {
                        sFilePath = dlgFile.FileName;
                        mDoc.New(sFilePath);
                        mDoc.ReplaceContents((IMxdContents)pPageLayoutControl.PageLayout);
                        mDoc.Save(true, true);
                        pPageLayoutControl.DocumentFilename = sFilePath;
                        mDoc.Close();
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #23
0
        private void menuSaveDoc_Click(object sender, EventArgs e)
        {
            //execute Save Document command
            if (m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("地图文件已经准备完毕!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Example #24
0
        public override void OnClick()
        {
            ISecureContext secureContext = _context as ISecureContext;

            if (secureContext.YutaiProject == null || string.IsNullOrEmpty(secureContext.YutaiProject.MapDocumentName))
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Title = "选择要保存的位置和文档名称";
                DialogResult result = dialog.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }
                secureContext.YutaiProject.MapDocumentName = dialog.FileName;
            }

            if (_context.MainView.ControlType == GISControlType.MapControl)
            {
                if (_context.MainView.MapControl.CheckMxFile(secureContext.YutaiProject.MapDocumentName))
                {
                    //create a new instance of a MapDocument
                    IMapDocument mapDoc = new MapDocumentClass();
                    mapDoc.Open(secureContext.YutaiProject.MapDocumentName, string.Empty);

                    //Make sure that the MapDocument is not readonly
                    if (mapDoc.get_IsReadOnly(secureContext.YutaiProject.MapDocumentName))
                    {
                        MessageBox.Show("Map document is read only!");
                        mapDoc.Close();
                        return;
                    }

                    //Replace its contents with the current map
                    mapDoc.ReplaceContents((IMxdContents)_context.MainView.MapControl.Map);

                    //save the MapDocument in order to persist it
                    mapDoc.Save(mapDoc.UsesRelativePaths, false);

                    //close the MapDocument
                    mapDoc.Close();
                    return;
                }
            }
            else if (_context.MainView.ControlType == GISControlType.PageLayout)
            {
                if (_context.MainView.MapControl.CheckMxFile(secureContext.YutaiProject.MapDocumentName))
                {
                    //create a new instance of a MapDocument
                    IMapDocument mapDoc = new MapDocumentClass();
                    mapDoc.Open(secureContext.YutaiProject.MapDocumentName, string.Empty);

                    //Make sure that the MapDocument is not readonly
                    if (mapDoc.get_IsReadOnly(secureContext.YutaiProject.MapDocumentName))
                    {
                        MessageBox.Show("Map document is read only!");
                        mapDoc.Close();
                        return;
                    }

                    //Replace its contents with the current map
                    mapDoc.ReplaceContents((IMxdContents)_context.MainView.PageLayoutControl);

                    //save the MapDocument in order to persist it
                    mapDoc.Save(mapDoc.UsesRelativePaths, false);

                    //close the MapDocument
                    mapDoc.Close();
                    return;
                }
            }
        }
Example #25
0
        void IGMap.SaveMxd()
        {
            if (this._mapHook.CheckMxFile(this._mapHook.DocumentFilename))
            {
                //string a=((IMapDocument)this._mapHook).DocumentFilename;
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(this._mapHook.DocumentFilename, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(this._mapHook.DocumentFilename))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)this._mapHook.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Example #26
0
 /// <summary>
 /// 
 /// </summary>
 private void saveMapDocument(AxMapControl pAxMapControl)
 {
     IMxdContents pMxdC;
     pMxdC = pAxMapControl.Map as IMxdContents;
     IMapDocument pMapDocument = new MapDocumentClass();
     pMapDocument.Open(pAxMapControl.DocumentFilename, "");
     IActiveView pActiveView = pAxMapControl.Map as IActiveView;
     pMapDocument.ReplaceContents(pMxdC);
     if (pMapDocument == null) return;
     //检查地图文档是否是只读
     if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
     {
         MessageBox.Show("本地图文档是只读的,不能保存!");
         return;
     }
     //根据相对的路径保存地图文档
     pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
     MessageBox.Show("地图文档保存成功!");
 }
Example #27
0
        /// <summary>
        /// 保存mxd文档
        /// mapControl为地图控件的名称
        /// 日期2013-12-13
        /// lntu_GISer1
        /// </summary>
        public void SaveMxdFile(AxMapControl mapControl)
        {
            IMxdContents pMxdC;
             pMxdC = mapControl.ActiveView.FocusMap as IMxdContents;
             IMapDocument pMapDocument = new MapDocumentClass();
             if (mapControl.DocumentFilename != null)
             {
                 pMapDocument.Open(mapControl.DocumentFilename, "");
                 pMapDocument.ReplaceContents(pMxdC);
                 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename))
                 {

                     MessageBox.Show("当前地图文档为只读文档!");
                     return;
                 }
                 try
                 {
                     pMapDocument.Save(true, true);
                     MessageBox.Show("地图文档保存成功!");
                 }
                 catch (Exception e)
                 {
                     MessageBox.Show(e.Message);
                 }
             }

             //用当前的文件路径设置保存文件
        }
Example #28
0
        public static void SaveDocument2(AxMapControl axMapControl1)
        {
            try
            {

                //判断pMapDocument是否为空,

                //获取pMapDocument对象

                IMxdContents pMxdC;

                pMxdC = axMapControl1.Map as IMxdContents;

                IMapDocument pMapDocument = new MapDocumentClass();

                pMapDocument.Open(axMapControl1.DocumentFilename, "");

                IActiveView pActiveView = axMapControl1.Map as IActiveView;

                pMapDocument.ReplaceContents(pMxdC);

                if (pMapDocument == null) return;

                //检查地图文档是否是只读

                if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
                {

                    MessageBox.Show("本地图文档是只读的,不能保存!");

                    return;

                }

                //根据相对的路径保存地图文档

                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);

                MessageBox.Show("地图文档保存成功!");

            }

            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);

            }
        }
Example #29
0
        // File menu items
        void fileToolStripMenuItems_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
            if (menuItem == null)
                return;
            ICommand command = null;
            string itemName = menuItem.Name;
            switch (itemName)
            {
                case "newDocToolStripMenuItem":
                    command = new CreateNewDocCmd();
                    command.OnCreate(m_MapControl.Object);
                    command.OnClick();
                    break;
                case "openDocToolStripMenuItem":
                    command = new ControlsOpenDocCommandClass();
                    command.OnCreate(m_MapControl.Object);
                    command.OnClick();
                    break;
                case "saveasStripMenuItem":
                    command = new ControlsSaveAsDocCommandClass();
                    command.OnCreate(m_MapControl.Object);
                    command.OnClick();
                    break;
                case "saveDocToolStripMenuItem":
                    if (m_MapControl.CheckMxFile(m_DocmentFileName))
                    {
                        IMapDocument mapDoc = new MapDocumentClass();
                        mapDoc.Open(m_DocmentFileName, string.Empty);
                        if (!mapDoc.get_IsReadOnly(m_DocmentFileName))
                        {
                            mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map);
                            mapDoc.Save(mapDoc.UsesRelativePaths, false);
                            mapDoc.Close();
                        }
                        else
                            MessageBox.Show("Cann't be save because of read-only document");
                    }
                    break;
                case "exitDocToolStripMenuItem":
                    DialogResult res = MessageBox.Show("Whether to save the current document?", "AOView", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (res == DialogResult.Yes)
                    {
                        command = new ControlsSaveAsDocCommandClass();
                        command.OnCreate(axMapControl1.Object);
                        command.OnClick();
                    }
                    Application.Exit();
                    break;

                default:
                    break;
            }
        }
Example #30
0
        public void OnClick()
        {
            //// 首先确认当前地图文档是否有效
            //if (null != m_pageLayoutControl.DocumentFilename && m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename))
            //{
            //// 创建一个新的地图文档实例
            //IMapDocument mapDoc = new MapDocumentClass();  // 打开当前地图文档
            //mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty);  // 用 PageLayout 中的文档替换当前文档中的 PageLayout 部分
            //mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);  // 保存地图文档
            //mapDoc.Save(mapDoc.UsesRelativePaths, false);
            //mapDoc.Close();

            //m_mapDocument = this.hk.Document;
            //if (m_mapDocument.get_IsReadOnly(m_mapDocument.DocumentFilename))
            //{
            //    MessageBox.Show("This map document is read only!");
            //    return;
            //}
            //m_mapDocument.Save(m_mapDocument.UsesRelativePaths, true);
            //MessageBox.Show("Changes saved successfully!");

            //execute Save Document command
            //m_mapDocumentName = m_mapControl.DocumentFilename;
            if (m_mapControl.DocumentFilename != null && m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                //m_mapControl.CheckMxFile(m_mapDocumentName);
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
            else {
                cmd = new ControlsSaveAsDocCommandClass();
                cmd.OnCreate(this.m_mapControl);
                cmd.OnClick();
            }
        }