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();
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
 private void SaveMapDoc()
 {
     if (null != m_pagelayoutcontrol.DocumentFilename && m_MapControl.CheckMxFile(m_pagelayoutcontrol.DocumentFilename))
     {
         IMapDocument mapDoc = new MapDocumentClass();
         mapDoc.Open(m_pagelayoutcontrol.DocumentFilename, string.Empty);
         mapDoc.ReplaceContents((IMxdContents)m_pagelayoutcontrol.PageLayout);
         mapDoc.Save(mapDoc.UsesRelativePaths, false);
         mapDoc.Close();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 加载Mxd
 /// </summary>
 /// <param name="mapControlDefault">当前视图mapcontrol</param>
 /// <param name="strFilePath">文件路径-可以为相对路径</param>
 /// <param name="mapNameOrIndex">地图名称或者索引,默认为空</param>
 /// <param name="password">文档密码,默认为空</param>
 public static void Load(IMapControlDefault mapControlDefault, string strFilePath, object mapNameOrIndex = null, object password = null)
 {
     if (mapNameOrIndex == null)
     {
         mapNameOrIndex = Type.Missing;
     }
     if (password == null)
     {
         password = Type.Missing;
     }
     if (mapControlDefault.CheckMxFile(strFilePath))
     {
         mapControlDefault.LoadMxFile(strFilePath, mapNameOrIndex, password);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 加载Mxd
 /// </summary>
 /// <param name="mapControlDefault">当前视图mapcontrol</param>
 /// <param name="strFilePath">文件路径-可以为相对路径</param>
 /// <param name="mapNameOrIndex">地图名称或者索引,默认为空</param>
 /// <param name="password">文档密码,默认为空</param>
 public static void Load(IMapControlDefault mapControlDefault, string strFilePath, object mapNameOrIndex = null, object password = null)
 {
     if (mapNameOrIndex == null)
     {
         mapNameOrIndex = Type.Missing;
     }
     if (password == null)
     {
         password = Type.Missing;
     }
     if (mapControlDefault.CheckMxFile(strFilePath))
     {
         mapControlDefault.LoadMxFile(strFilePath, mapNameOrIndex, password);
     }
 }
Esempio n. 6
0
 public bool LoadMapDocument(IMapControlDefault pMapControl, string sMxDocID)
 {
     try
     {
         if (pMapControl == null)
         {
             MessageBox.Show("地图文档加载失败,控件 MapControl 加载失败。", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(false);
         }
         if (string.IsNullOrEmpty(sMxDocID.Trim()))
         {
             MessageBox.Show("地图文档加载失败,文档ID " + sMxDocID + " 错误。", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(false);
         }
         string path = null;
         path = UtilFactory.GetConfigOpt().RootPath + @"\" + UtilFactory.GetConfigOpt().GetConfigValue(sMxDocID);
         if (!File.Exists(path))
         {
             MessageBox.Show("地图文档加载失败,文档文件 " + path + " 不存在。", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(false);
         }
         if (!pMapControl.CheckMxFile(path))
         {
             MessageBox.Show("地图文档加载失败,文档文件 " + path + " 内存在错误。", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(false);
         }
         pMapControl.LoadMxFile(path, null, null);
         IActiveView activeView = pMapControl.ActiveView;
         if (activeView.GraphicsContainer != null)
         {
             IViewManager manager          = activeView as IViewManager;
             ISelection   elementSelection = manager.ElementSelection;
             activeView.Selection = elementSelection;
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "LoadMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }