/// <summary> /// 获取某个路径下的MPJ文件 /// </summary> /// <param name="dirInfo"></param> private void get_MPJ_File(DirectoryInfo dirInfo) { advTreeMPJ.Nodes.Clear(); int count = 0; foreach (FileInfo file in dirInfo.GetFiles()) { if (file.Extension.Equals(".MPJ")) { count++;//用于显示进度条数据 Node pNode = new Node(); pNode.Text = file.Name; advTreeMPJ.Nodes.Add(pNode); //打开工程文件 加载工程下的图层文件 WorkSpace.IMxWorkSpace ws = new WorkSpace.MxWorkSpaceClass(); ws.Open(file.DirectoryName + "\\" + file.Name, WorkSpace.EnumOpenMode.OpenReadOnly); XMap map = ws.GetMapByName(file.Name.Split('.')[0]); ws.ActiveMap = map; //遍历工程文件下的所有图层文件 for (int i = 1; i <= map.LayerCount; i++) { IXMapLayer mapLayer = map.get_Layer(i); Node childNode = new Node(); childNode.Text = mapLayer.LayerName; pNode.Nodes.Add(childNode); } ws.Close(WorkSpace.EnumCloseMode.NoDlgDiscard); SetTextMessage(count * 100 / dirInfo.GetFiles().Length); } } }
//更新工程文件以及该工程文件的图层文件 private void tsmiMPJFileUpdate_Click(object sender, EventArgs e) { UpdateMPJFile umpjdlg = new UpdateMPJFile(this); if (umpjdlg.ShowDialog() == DialogResult.OK) { //如果需要备份 先备份MPJ文件 if (SwichBtnVale) { //备份文件 BackupFile(this.advTreeMPJ.SelectedNode.Text, MPJ_Path, SaveMPJFilePath); foreach (Node n in this.advTreeMPJ.SelectedNode.Nodes) { BackupFile(n.Text, MPJ_Path, SaveMPJFilePath); } //先删除MPJ文件以及该工程文件下的图层文件 DeleteFile(this.advTreeMPJ.SelectedNode.Text, MPJ_Path); foreach (Node n in this.advTreeMPJ.SelectedNode.Nodes) { DeleteFile(n.Text, MPJ_Path); } //更新MPJ文件 UpdateFile(NewMPJFile, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path); //打开工程文件 更新工程下的图层文件 WorkSpace.IMxWorkSpace ws = new WorkSpace.MxWorkSpaceClass(); ws.Open(NewMPJFilePath, WorkSpace.EnumOpenMode.OpenReadOnly); XMap map = ws.GetMapByName(NewMPJFile.Replace(".MPJ", "")); ws.ActiveMap = map; for (int i = 1; i <= map.LayerCount; i++) { IXMapLayer mapLayer = map.get_Layer(i); UpdateFile(mapLayer.LayerName, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path); } ws.Close(WorkSpace.EnumCloseMode.NoDlgDiscard); } else//不备份直接更新 { //先删除MPJ文件以及该工程文件下的图层文件 DeleteFile(this.advTreeMPJ.SelectedNode.Text, MPJ_Path); foreach (Node n in this.advTreeMPJ.SelectedNode.Nodes) { DeleteFile(n.Text, MPJ_Path); } //更新MPJ文件 UpdateFile(NewMPJFile, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path); //打开工程文件 更新工程下的图层文件 WorkSpace.IMxWorkSpace ws = new WorkSpace.MxWorkSpaceClass(); ws.Open(NewMPJFilePath, WorkSpace.EnumOpenMode.OpenReadOnly); XMap map = ws.GetMapByName(NewMPJFile.Replace(".MPJ", "")); ws.ActiveMap = map; for (int i = 1; i <= map.LayerCount; i++) { IXMapLayer mapLayer = map.get_Layer(i); UpdateFile(mapLayer.LayerName, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path); } ws.Close(WorkSpace.EnumCloseMode.NoDlgDiscard); } } }