/// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenMxdCommand.OnClick implementation

            //launch a new OpenFile dialog
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();
            pOpenFileDialog.Filter = "Map Documents (*.mxd)|*.mxd";
            pOpenFileDialog.Multiselect = false;
            pOpenFileDialog.Title = "Open Map Document";
            if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string docName = pOpenFileDialog.FileName;

                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {

                    pMapControl.LoadMxFile(pOpenFileDialog.FileName, null, null);

                    // set the first map as the active view

                    pMapControl.ActiveView.Refresh();

                    pMapDoc.Close();

                }
            }
        }
예제 #2
0
        /// <summary>
        /// Opens mxd document.
        /// </summary>
        /// <param name="sMxdFilePath">The  MXD file path.</param>
        public static void OpenDocument(string sMxdFilePath)
        {
            IMapDocument mapDocument = new MapDocumentClass();

            if (mapDocument.get_IsPresent(sMxdFilePath) && !mapDocument.get_IsPasswordProtected(sMxdFilePath))
            {
                mapDocument.Open(sMxdFilePath, "");
                try
                {
                    IMap map = mapDocument.get_Map(0);
                    mapDocument.SetActiveView((IActiveView)map);
                    //EnviVars.instance.Synchronizer.PageLayoutControl.PageLayout = mapDocument.PageLayout;
                    //EnviVars.instance.Synchronizer.ReplaceMap(map);
                    EnviVars.instance.MapControl.Map = map;
                    EnviVars.instance.MainForm.Text  = sMxdFilePath;
                }
                catch (Exception ex)
                {
                    //_logger.Log(LogLevel.Error, EventType.UserManagement, null, ex);
                    Log.WriteLog(typeof(MapAPI), ex);
                }
                finally
                {
                    mapDocument.Close();
                }
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenMxdCommand.OnClick implementation

            //launch a new OpenFile dialog
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();

            pOpenFileDialog.Filter      = "Map Documents (*.mxd)|*.mxd";
            pOpenFileDialog.Multiselect = false;
            pOpenFileDialog.Title       = "Open Map Document";
            if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string docName = pOpenFileDialog.FileName;

                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    pMapControl.LoadMxFile(pOpenFileDialog.FileName, null, null);

                    // set the first map as the active view

                    pMapControl.ActiveView.Refresh();

                    pMapDoc.Close();
                }
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenNewMapDocument.OnClick implementation
            //launch a new OpenFile dialog
            System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
            dlg.Multiselect = false;
            dlg.Title       = "Open Map Document";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string       docName = dlg.FileName;
                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    // 以下3.3.3.1代码

                    /* pMapControl.LoadMxFile(dlg.FileName, null, null);
                     * pMapControl.ActiveView.Refresh();
                     * pMapDoc.Close();                     */
                    // 以下3.3.3.5代码
                    pMapDoc.Open(docName, string.Empty);
                    IMap map = pMapDoc.get_Map(0);
                    pMapDoc.SetActiveView((IActiveView)map);
                    pControlsSynchronizer.PageLayoutControl.PageLayout = pMapDoc.PageLayout;
                    pControlsSynchronizer.ReplaceMap(map);
                    pMapDoc.Close();
                }
            }
        }
        /// <summary>
        /// 作用:打开TemplateMapDocument
        /// 作者:汪建龙
        /// 编写时间:2016年12月23日11:18:34
        /// </summary>
        /// <returns></returns>
        private IMapDocument OpenTemplateDocument()
        {
            try
            {
                IMapDocument tempMapDocumnet = new MapDocumentClass();
                if (!tempMapDocumnet.get_IsPresent(TemplateMxdFileName) ||
                    !tempMapDocumnet.get_IsMapDocument(TemplateMxdFileName) ||
                    tempMapDocumnet.get_IsPasswordProtected(TemplateMxdFileName) ||
                    tempMapDocumnet.get_IsRestricted(TemplateMxdFileName))
                {
                    var message = string.Format("路径:\"{0}\"下的地图文档不正确,请拷贝该文件到该路径下", _templateMxdFileName);
                    System.Diagnostics.Trace.WriteLine(message);
                    return(null);
                }

                tempMapDocumnet.Open(TemplateMxdFileName, null);

                if (tempMapDocumnet.DocumentVersion == esriMapDocumentVersionInfo.esriMapDocumentVersionInfoFail)
                {
                    var message = string.Format("路径:\"{0}\"下的地图文档版本不正确,请拷贝该文件到该路径下", TemplateMxdFileName);
                    return(null);
                }

                return(tempMapDocumnet);
            }catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
                return(null);
            }
        }
예제 #6
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            //launch a new OpenFile dialog
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
            dlg.Multiselect = false;
            dlg.Title       = "Open Map Document";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string docName = dlg.FileName;

                IMapDocument mapDoc = new MapDocumentClass();
                if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
                {
                    mapDoc.Open(docName, string.Empty);

                    // set the first map as the active view
                    IMap map = mapDoc.get_Map(0);
                    mapDoc.SetActiveView((IActiveView)map);

                    m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout;

                    m_controlsSynchronizer.ReplaceMap(map);

                    mapDoc.Close();

                    m_sDocumentPath = docName;
                }
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public void OnClickAutomatic(string docName)
        {
            IMapDocument mapDoc = new MapDocumentClass();

            if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
            {
                mapDoc.Open(docName, string.Empty);
                IMap map = mapDoc.get_Map(0);
                m_controlsSynchronizer.ReplaceMap(map);
                mapDoc.Close();
            }
        }
예제 #8
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public void OnClickAutomatic(string docName)
        {
            IMapDocument mapDoc = new MapDocumentClass();

            if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
            {
                mapDoc.Open(docName, string.Empty);
                IMap map = mapDoc.get_Map(0);
                m_controlsSynchronizer.ReplaceMap(map);
                mapDoc.Close();
            }


            //"C:\\Study\\Data\\Morphing Data\\Administrative Boundary\\Hunan\\Hunan.mxd"
        }
예제 #9
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenTool.OnClick implementation
            OpenFileDialog OpenMXD = new OpenFileDialog(); //可实例化类

            OpenMXD.Title       = "打开地图";                  // OpenFileDialog类的属性Title
            OpenMXD.Multiselect = false;
            OpenMXD.Filter      = "Map Documents (*.mxd)|*.mxd";
            if (OpenMXD.ShowDialog() == DialogResult.OK) //ShowDialog是类的方法
            {
                string       docName = OpenMXD.FileName;
                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    pMapControl.LoadMxFile(OpenMXD.FileName, null, null);
                    pMapControl.ActiveView.Refresh();
                    pMapDoc.Close();
                }
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenNewMapDocument.OnClick implementation
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
            dlg.Multiselect = false;
            dlg.Title       = "Open Map Document";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string       docName = dlg.FileName;
                IMapDocument mapDoc  = new MapDocumentClass();
                if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
                {
                    mapDoc.Open(docName, string.Empty);
                    IMap map = mapDoc.get_Map(0);
                    m_controlsSynchronizer.ReplaceMap(map);
                    mapDoc.Close();
                }
            }
        }
예제 #11
0
        /// <summary>
        /// 作用:MapControl加载mxd文件
        /// 作者:汪建龙
        /// 编写时间:2016年12月26日09:49:25
        /// </summary>
        /// <param name="mapControl"></param>
        /// <param name="mxdFile"></param>
        public static void Load(this IMapControl2 mapControl, string mxdFile)
        {
            try
            {
                if (System.IO.File.Exists(mxdFile) == false)
                {
                    return;
                }

                IMapDocument mapDocument = new MapDocumentClass();
                if (!mapDocument.get_IsPresent(mxdFile) ||
                    !mapDocument.get_IsMapDocument(mxdFile) ||
                    mapDocument.get_IsPasswordProtected(mxdFile) ||
                    mapDocument.get_IsRestricted(mxdFile))
                {
                    string message = string.Format("路径:\"{0}\"下的地图文档不正确,请拷贝文件到该路径下。", mxdFile);
                    System.Diagnostics.Trace.WriteLine(message);
                }
                else
                {
                    mapDocument.Open(mxdFile, null);
                    if (mapDocument.DocumentVersion == esriMapDocumentVersionInfo.esriMapDocumentVersionInfoFail)
                    {
                        string message = string.Format("路径:\"{0}\"下的地图文档版本不正确,请拷贝该文件到该路径下。", mxdFile);
                        System.Diagnostics.Trace.WriteLine(message);
                    }
                    else if (mapDocument.MapCount > 0)
                    {
                        IMap map = mapDocument.get_Map(0);
                        mapControl.Map = map;
                    }
                }
            }catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
            }
        }
예제 #12
0
        protected void OpenPastureMapDoc(Pasture pasture)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(pasture.strMapDoc) &&
                !mapDoc.get_IsPasswordProtected(pasture.strMapDoc))
            {
                mapDoc.Open(pasture.strMapDoc, string.Empty);

                // set the first map as the active view
                m_pastureMap = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)m_pastureMap);
                mapDoc.Close();
            }
        }
예제 #13
0
        public override bool LoadMap(string filePath)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(filePath) && !mapDoc.get_IsPasswordProtected(filePath))
            {
                mapDoc.Open(filePath, string.Empty);
                // set the first map as the active view
                IMap map = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)map);
                this._axLayoutCtrl.PageLayout = mapDoc.PageLayout;
                this._mapAndLayoutSync.ReplaceMap(map);
                mapDoc.Close();
                this._mapFile = filePath;
                return true;
            }
            else
            {
                return false;
            }

            /*
            if (this._axMapCtrl.CheckMxFile(filePath))
            {
                


                this._axMapCtrl.LoadMxFile(filePath, Type.Missing, Type.Missing);
                this._axMapCtrl.Enabled = true;
                this._mapFile = filePath;
                return true;
            }
            else
            {
                return false;
            }
            */ 
        }
		private void cmdLoadDoc_Click(object sender, System.EventArgs e)
		{
			//Open a file dialog for selecting map documents
			openFileDialog1.Title = "Browse Map Document";
			openFileDialog1.Filter = "Map Documents (*.mxd, *.mxt, *.pmf)|*.pmf; *.mxt; *.mxd";
			openFileDialog1.ShowDialog();

			//Exit if no map document is selected
			string sFilePath = openFileDialog1.FileName;
			if (sFilePath == "") return;

			bool bPass, bIsMapDoc;
			IMapDocument ipMapDoc;
			ipMapDoc = new MapDocumentClass();

			//Check if the map document is password protected
			bPass = ipMapDoc.get_IsPasswordProtected(sFilePath);

			if(bPass)
			{
				//Disable the main form
				this.Enabled = false;

				//Show the password dialog
				frmPassword Form2 = new frmPassword();
				Form2.ShowDialog (this);
				int check = Form2.Check; 
					
				//OK button pressed					
				if (check == 1)
				{
					try
					{
						//Set a waiting cursor
						Cursor.Current = Cursors.WaitCursor;
								
						//Load the password protected map
						axPageLayoutControl1.LoadMxFile(sFilePath, Form2.Password); 
						txtPath.Text = sFilePath;
						this.Enabled = true;

						//Set a default cursor
						Cursor.Current = Cursors.Default; 
					}
					catch
					{
						this.Enabled = true;
						MessageBox.Show("The Password was incorrect!");
					}
				}
				else
				{
					this.Enabled = true;
				}
			}
			else  
			{
				//Check whether the file is a map document
				bIsMapDoc = axPageLayoutControl1.CheckMxFile(sFilePath);
				
				if(bIsMapDoc)
				{
					Cursor.Current = Cursors.WaitCursor;
					
					//Load the Mx document	
					axPageLayoutControl1.LoadMxFile(sFilePath, Type.Missing); 
					txtPath.Text = sFilePath;
					//Set a default cursor
					Cursor.Current = Cursors.Default; 
				}
				else
				{
					MessageBox.Show(sFilePath + " is not a valid ArcMap document");
					sFilePath = "";
				}
			}
		}
예제 #15
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IPageLayoutControl3 pPageLayoutControl = null;

            try
            {
                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;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            try
            {
                if (string.IsNullOrEmpty(m_strDocName))
                {
                    OpenFileDialog dlgFile = new OpenFileDialog();//以对话框选择文档路径
                    dlgFile.Title  = "打开一个地图文档";
                    dlgFile.Filter = "Map Documents(*.mxd)|*.mxd";
                    if (dlgFile.ShowDialog() == DialogResult.OK)
                    {
                        m_strDocName = dlgFile.FileName;
                    }
                }
                IMapDocument mapDoc = new MapDocumentClass(); //地图文档对象
                IMap         map    = null;
                if (mapDoc.get_IsPresent(m_strDocName) && !mapDoc.get_IsPasswordProtected(m_strDocName))
                {
                    mapDoc.Open(m_strDocName, string.Empty);

                    IMaps maps = new Maps();
                    for (int i = 0; i < mapDoc.MapCount; i++)
                    {
                        maps.Add(mapDoc.get_Map(i));
                    }
                    // set the first map as the active view
                    map = mapDoc.get_Map(0);
                    mapDoc.SetActiveView((IActiveView)map);

                    m_controlsSynchronizer.PageLayoutControl.PageLayout       = mapDoc.PageLayout;
                    m_controlsSynchronizer.PageLayoutControl.Printer          = mapDoc.Printer;
                    m_controlsSynchronizer.PageLayoutControl.DocumentFilename = m_strDocName;
                    //m_controlsSynchronizer.ReplaceMap(map);
                    m_controlsSynchronizer.AddNewMaps(maps);

                    mapDoc.Close();

                    m_strDocName = string.Empty;
                }

                /////////////////////////////
                //关闭属性表
                if (m_barTable.Visible == true)
                {
                    if (m_AttributeRemove != null)
                    {
                        m_AttributeRemove.Clear();
                        m_AttributeRemove.Columns.Clear();
                        m_barTable.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "打开地图文档失败");
            }
        }
    /// <summary>
    /// Occurs when this command is clicked
    /// </summary>
    public override void OnClick()
    {
      //launch a new OpenFile dialog
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Filter = "Map Documents (*.mxd)|*.mxd";
      dlg.Multiselect = false;
      dlg.Title = "Open Map Document";
      if (dlg.ShowDialog() == DialogResult.OK)
      {
        string docName = dlg.FileName;

        IMapDocument mapDoc = new MapDocumentClass();
        if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
        {
          mapDoc.Open(docName, string.Empty);

          // set the first map as the active view
          IMap map = mapDoc.get_Map(0);
          mapDoc.SetActiveView((IActiveView)map);

          m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout;

          m_controlsSynchronizer.ReplaceMap(map);

          mapDoc.Close();

          m_sDocumentPath = docName;
        }
      }
    }
예제 #17
0
        private void cmdLoadDoc_Click(object sender, System.EventArgs e)
        {
            //Open a file dialog for selecting map documents
            openFileDialog1.Title  = "Browse Map Document";
            openFileDialog1.Filter = "Map Documents (*.mxd, *.mxt, *.pmf)|*.pmf; *.mxt; *.mxd";
            openFileDialog1.ShowDialog();

            //Exit if no map document is selected
            string sFilePath = openFileDialog1.FileName;

            if (sFilePath == "")
            {
                return;
            }

            bool         bPass, bIsMapDoc;
            IMapDocument ipMapDoc;

            ipMapDoc = new MapDocumentClass();

            //Check if the map document is password protected
            bPass = ipMapDoc.get_IsPasswordProtected(sFilePath);

            if (bPass)
            {
                //Disable the main form
                this.Enabled = false;

                //Show the password dialog
                frmPassword Form2 = new frmPassword();
                Form2.ShowDialog(this);
                int check = Form2.Check;

                //OK button pressed
                if (check == 1)
                {
                    try
                    {
                        //Set a waiting cursor
                        Cursor.Current = Cursors.WaitCursor;

                        //Load the password protected map
                        axPageLayoutControl1.LoadMxFile(sFilePath, Form2.Password);
                        txtPath.Text = sFilePath;
                        this.Enabled = true;

                        //Set a default cursor
                        Cursor.Current = Cursors.Default;
                    }
                    catch
                    {
                        this.Enabled = true;
                        MessageBox.Show("The Password was incorrect!");
                    }
                }
                else
                {
                    this.Enabled = true;
                }
            }
            else
            {
                //Check whether the file is a map document
                bIsMapDoc = axPageLayoutControl1.CheckMxFile(sFilePath);

                if (bIsMapDoc)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    //Load the Mx document
                    axPageLayoutControl1.LoadMxFile(sFilePath, Type.Missing);
                    txtPath.Text = sFilePath;
                    //Set a default cursor
                    Cursor.Current = Cursors.Default;
                }
                else
                {
                    MessageBox.Show(sFilePath + " is not a valid ArcMap document");
                    sFilePath = "";
                }
            }
        }
예제 #18
0
        /// <summary>
        /// Called when the user clicks a command.
        /// </summary>
        /// <remarks>Note to inheritors: override OnClick and use this method to
        ///             perform the actual work of the custom command.</remarks>
        public override void OnClick()
        {
            //Logger logger = new Logger();
            try
            {
                EnviVars.instance.MainForm.UseWaitCursor = true;
                //System.Windows.Forms.Cursor.Current=System.Windows.Forms.Cursors.WaitCursor;
                bool isCurrrentNew = (String.IsNullOrEmpty(EnviVars.instance.MapControl.DocumentFilename) &&
                                      EnviVars.instance.MapControl.LayerCount > 0);
                if ((!String.IsNullOrEmpty(EnviVars.instance.MapControl.DocumentFilename) &&
                     EnviVars.instance.MapControl.CheckMxFile(EnviVars.instance.MapControl.DocumentFilename)) || isCurrrentNew)
                {
                    DialogResult res = XtraMessageBox.Show("保存当前文档?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (res == DialogResult.Yes)
                    {
                        //if yes, launch the Save command
                        //ICommand command = new CmdSaveFile();
                        //command.OnCreate(EnviVars.instance.MapControl.Object);
                        //command.OnClick();
                        IMxdContents mxdContents = EnviVars.instance.MapControl.Map as IMxdContents;
                        MapAPI.SaveMapDocument(mxdContents, EnviVars.instance.MapControl.DocumentFilename.ToString(), false);
                    }
                }
                //logger.Log(LogLevel.Info, EventType.UserManagement, AppMessage.MSG0090, null);
                //launch the OpenMapDoc command

                //ICommand OpenMapDoc = new ControlsOpenDocCommandClass();
                //OpenMapDoc.OnCreate(this.m_hookHelper.Hook);
                //OpenMapDoc.OnClick();

                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
                dlg.Multiselect = false;
                dlg.Title       = "打开文档";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string docName = dlg.FileName;
                    string taskXml = docName.Substring(0, docName.LastIndexOf(".")) + ".xml";
                    if (!File.Exists(taskXml))
                    {
                        XtraMessageBox.Show("任务描述文件不存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }

                    if (!Task.ParseTask(taskXml))
                    {
                        return;
                    }
                    EnviVars.instance.CurrentTask = taskXml;
                    IMapDocument mapDoc = new MapDocumentClass();
                    if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
                    {
                        //mapDoc.Open(docName, string.Empty);
                        // set the first map as the active view
                        //IMap map = mapDoc.get_Map(0);
                        //mapDoc.SetActiveView((IActiveView)map);
                        //EnviVars.instance.PageLayoutControl.PageLayout = mapDoc.PageLayout;
                        //EnviVars.instance.Synchronizer.ReplaceMap(map);
                        //EnviVars.instance.MapControl.Map = map;
                        //mapDoc.Close();
                        EnviVars.instance.MapControl.DocumentFilename = docName;
                        EnviVars.instance.MapControl.LoadMxFile(docName);
                        EnviVars.instance.history.AddTask(docName);

                        //CommandAPI.AddRecentFile(docName, FileType.MXD);
                        //CommandAPI.SaveRecentFilesInfo();
                        //logger.Log(LogLevel.Info, EventType.UserManagement, AppMessage.MSG0090, null);
                    }
                }
            }
            catch (Exception ex)
            {
                //logger.Log(LogLevel.Error, EventType.UserManagement, AppMessage.MSG0090, ex);
                Log.WriteLog(typeof(CmdOpenMxd), ex);
            }
            finally
            {
                EnviVars.instance.MainForm.Text          = EnviVars.instance.MapControl.DocumentFilename;
                EnviVars.instance.MainForm.UseWaitCursor = false;
            }
        }
예제 #19
0
 private IMapDocument OpenMapDocument(string sFileName, string sPassword)
 {
     try
     {
         if (sFileName == null)
         {
             sFileName = "";
         }
         if (sPassword == null)
         {
             sPassword = "";
         }
         if (string.IsNullOrEmpty(sFileName))
         {
             OpenFileDialog dialog = new OpenFileDialog {
                 Filter      = "所有支持文件|*.mxd;*.mxt;*.pmf;*.lyr|地图文档 (*.mxd)|*.mxd|地图模板 (*.mxt)|*.mxt|发布地图 (*.pmf)|*.pmf|地图图层 (*.lyr)|*.lyr",
                 Multiselect = false,
                 Title       = "选择的地图文件"
             };
             if (dialog.ShowDialog() != DialogResult.OK)
             {
                 return(null);
             }
             sFileName = dialog.FileName;
             dialog    = null;
         }
         if (string.IsNullOrEmpty(sFileName))
         {
             return(null);
         }
         if (!File.Exists(sFileName))
         {
             Interaction.MsgBox("地图文档加载失败,文档文件 " + sFileName + " 不存在。", MsgBoxStyle.Exclamation, "错误警告");
             return(null);
         }
         IMapDocument document = null;
         document = new MapDocumentClass();
         if (!document.get_IsMapDocument(sFileName))
         {
             Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是 MapDocument 文件。", MsgBoxStyle.Exclamation, "失败");
             return(null);
         }
         if (document.get_IsRestricted(sFileName))
         {
             Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败");
             return(null);
         }
         if (document.get_IsPasswordProtected(sFileName))
         {
             document.Open(sFileName, sPassword);
         }
         else
         {
             document.Open(sFileName, "");
         }
         return(document);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "OpenMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
예제 #20
0
        protected void OpenAdministrativeMapDoc(string adminMapDoc)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(adminMapDoc) &&
                !mapDoc.get_IsPasswordProtected(adminMapDoc))
            {
                mapDoc.Open(adminMapDoc, string.Empty);

                // set the first map as the active view
                m_adminMap = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)m_adminMap);
                mapDoc.Close();

                m_mapcontrol.Map = m_adminMap;
            }
        }