Exemplo n.º 1
0
        //另存为
        public static void SaveDocAs(AxMapControl mapControl, AxPageLayoutControl pageLayoutControl = null)
        {
            IMapDocument pMapDocument = new MapDocumentClass();

            SaveFileDialog saveDlg = new SaveFileDialog();

            saveDlg.Title  = "地图文档另存为";
            saveDlg.Filter = "mxd文件|*.mxd|所有文件(添加后缀名)|*.*";
            saveDlg.ShowDialog();
            string strDocFileN = saveDlg.FileName;

            if (strDocFileN == string.Empty)
            {
                return;
            }
            pMapDocument.Open(mapControl.DocumentFilename);
            if (strDocFileN == mapControl.DocumentFilename)
            {
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                return;
            }
            else
            {
                pMapDocument.SaveAs(strDocFileN, true, true);
                MessageBox.Show("保存成功!", "信息提示");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 确定之后将文档进行默认保存
        /// </summary>
        /// <param name="mapControlDefault">当前视图mapcontrol</param>
        /// <returns></returns>
        public static bool SaveAsMxd(string saveAsPath, IMapControlDefault mapControlDefault, bool useRelativePath)
        {
            IMxdContents pMxdContents;

            pMxdContents = mapControlDefault.Map as IMxdContents;
            IMapDocument pMapDocument = new MapDocumentClass();

            pMapDocument.Open(mapControlDefault.DocumentFilename, "");
            pMapDocument.ReplaceContents(pMxdContents);

            pMapDocument.SaveAs(saveAsPath, useRelativePath, false);
            pMapDocument.Close();
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 另存为 mdx
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 另存为ToolStripMenuItem_Click(Object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "地图文档(*.mxd)|*.mxd";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                IMxdContents pMxdC;
                pMxdC = axMapControl1.Map as IMxdContents;
                IMapDocument pMapDocument = new MapDocumentClass();
                pMapDocument.Open(axMapControl1.DocumentFilename, "");

                pMapDocument.ReplaceContents(pMxdC);
                pMapDocument.SaveAs(saveFileDialog.FileName);
            }
        }
Exemplo n.º 4
0
        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IMxdContents pMxdC;

            pMxdC = axMapControl1.Map as IMxdContents;
            IMapDocument pMapDocument;

            pMapDocument = new MapDocumentClass();
            pMapDocument.Open(axMapControl1.DocumentFilename, "");
            pMapDocument.ReplaceContents(pMxdC);
            SaveFileDialog sfd = new SaveFileDialog();

            //sfd.InitialDirectory = "D:\\esri\\chart\\辽东湾海图\\";
            sfd.InitialDirectory = initPath;
            sfd.Title            = "地图文档另存";
            sfd.Filter           = "地图文档(*.mxd)|*.mxd";
            sfd.RestoreDirectory = true;
            sfd.FilterIndex      = 1;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                pMapDocument.SaveAs(sfd.FileName);
                MessageBox.Show("另存成功");
            }
        }
Exemplo n.º 5
0
        private void SaveInitState()
        {
            Plugin.Application.IAppDBIntegraRef _pDBIntegra = _hook as Plugin.Application.IAppDBIntegraRef;
            string strTmpPath  = Application.StartupPath + "\\..\\Temp\\Tmpmxd" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".mxd";
            string strTmpPath2 = Application.StartupPath + "\\..\\Temp\\Tmpmxd" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + "_.mxd";

            if (!System.IO.Directory.Exists(Application.StartupPath + "\\..\\Temp"))
            {
                System.IO.Directory.CreateDirectory(Application.StartupPath + "\\..\\Temp");
            }
            IMxdContents pMxdC;

            pMxdC = _pDBIntegra.MapControl.Map as IMxdContents;

            IMapDocument pMapDocument = new MapDocumentClass();

            //创建地图文档
            pMapDocument.New(strTmpPath);

            //保存信息
            IActiveView pActiveView = _pDBIntegra.MapControl.Map as IActiveView;

            pMapDocument.ReplaceContents(pMxdC);

            try//yjl20110817 防止保存时,其他程序也在打开这个文档而导致共享冲突从而使系统报错
            {
                pMapDocument.Save(true, true);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pMapDocument);
                pMapDocument = null;
                pMapDocument = new MapDocumentClass();
                pMapDocument.Open(strTmpPath, "");
                GeoLayerTreeLib.LayerManager.ModuleMap.SetLayersVisibleAttri(pMapDocument, true);
                ModPublicFun.WriteLog("pMapDocument.Save start");
                pMapDocument.SaveAs(strTmpPath2, true, true);
                ModPublicFun.WriteLog("pMapDocument.Save false");
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    ModPublicFun.WriteLog(ex.Message);
                }
            }
            pMapDocument.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pMapDocument);
            pMapDocument = null;
            try
            {
                System.IO.File.Delete(strTmpPath);
            }
            catch (Exception err2)
            {
            }
            if (System.IO.File.Exists(strTmpPath2))
            {
                SysGisTable mSystable            = new SysCommon.Gis.SysGisTable(Plugin.ModuleCommon.TmpWorkSpace);
                Dictionary <string, object> pDic = new Dictionary <string, object>();
                //参数名
                pDic.Add("SETTINGNAME", "初始加载地图文档");
                //参数数据类型
                pDic.Add("DATATYPE", "MxdFile");
                //参数描述
                //pDic.Add("DESCRIPTION", textBoxSettingDescription.Text);
                //参数值(分简单参数值和文件型参数值)

                IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();
                pBlobStream.LoadFromFile(strTmpPath2);
                pDic.Add("SETTINGVALUE2", pBlobStream);

                Exception err  = null;
                bool      bRes = false;
                if (mSystable.ExistData("SYSSETTING", "SETTINGNAME='初始加载地图文档'"))
                {
                    bRes = mSystable.UpdateRow("SYSSETTING", "SETTINGNAME='初始加载地图文档'", pDic, out err);
                }
                else
                {
                    bRes = mSystable.NewRow("SYSSETTING", pDic, out err);
                }
                if (!bRes)
                {
                    MessageBox.Show("保存出错:" + err.Message);
                }
                try
                {
                    System.IO.File.Delete(strTmpPath2);
                }
                catch (Exception err2)
                {
                }
            }
        }