private void btnImport_Click(object sender, EventArgs e) { if (this.folderBrowser.ShowDialog() == DialogResult.OK) { string folderProject = folderBrowser.SelectedPath; ProjectFileStructure pStructure = null; string errMsg = null; if (ProjectHelper.TestProjectFolder(folderProject, ref pStructure, ref errMsg)) { ProjectInfo projectInfo = null; if (ProjectHelper.ImportProject(pStructure, ref projectInfo)) { XtraMessageBox.Show("导入成功!"); Refresh(); } else { XtraMessageBox.Show("导入失败!"); return; } } else { XtraMessageBox.Show(string.Format("当前所选择的文件夹不是正确的项目文件夹:{0}!", errMsg)); return; } } }
public static bool ImportProject(ProjectFileStructure pFileStructure, ref ProjectInfo projectInfo) { if (pFileStructure == null) { return(false); } if (projectInfo == null) { projectInfo = new ProjectInfo(); } try { projectInfo.Folder = Path.Combine(m_WorkFolder, Guid.NewGuid().ToString());// pFileStructure.RootFolder; Directory.CreateDirectory(projectInfo.Folder); projectInfo.File = Path.Combine(projectInfo.Folder, FlyFile); File.Copy(pFileStructure.FlyFile, projectInfo.File); DataTable dtProejct = ExcelHelper.ReadData(pFileStructure.ProjectExcel); if (dtProejct != null && dtProejct.Rows.Count > 0) { projectInfo.Name = dtProejct.Rows[0][0] as string; projectInfo.Type = dtProejct.Rows[0][1] as string; projectInfo.Enterprise = dtProejct.Rows[0][2] as string; projectInfo.Address = dtProejct.Rows[0][3] as string; } List <SchemaInfo> schemaList = new List <SchemaInfo>(); foreach (SchemaFileStructure schemaStructure in pFileStructure.SchemaStruactures) { SchemaInfo schemaInfo = new SchemaInfo(); schemaInfo.Folder = System.IO.Path.Combine(projectInfo.Folder, System.IO.Path.GetFileName(schemaStructure.SchemaFolder)); schemaInfo.File = Path.Combine(schemaInfo.Folder, BuildingShp); DataTable dtSchema = ExcelHelper.ReadData(schemaStructure.SchemaExcel); if (dtSchema != null && dtSchema.Rows.Count > 0) { schemaInfo.Name = dtSchema.Rows[0][0] as string; schemaInfo.Type = dtSchema.Rows[0][1] as string; schemaInfo.BuildingArea = Convert.ToDouble(dtSchema.Rows[0][2]); schemaInfo.VegetationArea = Convert.ToDouble(dtSchema.Rows[0][3]); schemaInfo.RoadArea = Convert.ToDouble(dtSchema.Rows[0][4]); } schemaInfo.Project = projectInfo; Directory.CreateDirectory(schemaInfo.Folder); // 方案文件夹 string modelFolder = Path.Combine(schemaInfo.Folder, ModelFolder); // 模型文件夹 Directory.CreateDirectory(modelFolder); string[] modelFiles = Directory.GetFiles(schemaStructure.ModelFolder); // 模型 foreach (string strFile in modelFiles) { File.Copy(strFile, Path.Combine(modelFolder, Path.GetFileName(strFile))); } //schemaStructure.LocationExcel //File.Copy(m_LocationTemplateShp+".shp",schemaInfo.File); // shp //CopyShp(Path.Combine(schemaStructure.SchemaFolder, BuildingShp), Path.Combine(schemaInfo.Folder, BuildingShp)); //CopyShp(Path.Combine(schemaStructure.SchemaFolder, "Building"), schemaInfo.Folder,"Building"); CopyShp(Path.Combine(schemaStructure.SchemaFolder, "Building"), Path.Combine(schemaInfo.Folder, "Building")); // ESRI.ArcGIS.Geodatabase schemaList.Add(schemaInfo); } projectInfo.Schemas = schemaList; // 记录 AddProjectInfo(projectInfo); } catch { return(false); } return(true); }
public static bool TestProjectFolder(string strFolder, ref ProjectFileStructure pFileStructure, ref string errMsg) { if (!System.IO.Directory.Exists(strFolder)) { return(false); } ProjectFileStructure pTemp = new ProjectFileStructure(); pTemp.RootFolder = strFolder; pTemp.ProjectExcel = Path.Combine(strFolder, ProjectExcel); if (!File.Exists(pTemp.ProjectExcel)) { errMsg = "项目信息文件(Project.xls)不存在"; return(false); } pTemp.FlyFile = Path.Combine(strFolder, FlyFile); if (!File.Exists(pTemp.FlyFile)) { errMsg = "项目Fly文件不存在"; return(false); } pTemp.ImageFile = Path.Combine(strFolder, ImageFile); //if (!File.Exists(pTemp.ImageFile)) //{ // errMsg = "项目影像文件不存在"; // return false; //} pTemp.DemFile = Path.Combine(strFolder, ImageFile); //if (!File.Exists(pTemp.DemFile)) //{ // errMsg = "项目高程文件不存在"; // return false; //} string[] schemaFolders = Directory.GetDirectories(strFolder); if (strFolder == null || strFolder.Length == 0) { errMsg = "没有方案"; return(false); } List <SchemaFileStructure> sListTemp = new List <SchemaFileStructure>(); foreach (string schemaFolder in schemaFolders) { SchemaFileStructure sTemp = new SchemaFileStructure(); sTemp.SchemaFolder = schemaFolder; sTemp.SchemaExcel = Path.Combine(schemaFolder, SchemaExcel); if (!File.Exists(sTemp.SchemaExcel)) { continue; } sTemp.LocationExcel = Path.Combine(schemaFolder, LocationExcel); if (!File.Exists(sTemp.LocationExcel)) { continue; } sTemp.ModelFolder = Path.Combine(schemaFolder, ModelFolder); if (!Directory.Exists(sTemp.ModelFolder)) { continue; } sListTemp.Add(sTemp); } if (sListTemp.Count == 0) { errMsg = "当前文件夹下没有方案"; return(false); } pTemp.SchemaStruactures = sListTemp; pFileStructure = pTemp; return(true); }
public static bool TestProjectFolder(string strFolder, ref ProjectFileStructure pFileStructure, ref string errMsg) { if (!System.IO.Directory.Exists(strFolder)) return false; ProjectFileStructure pTemp = new ProjectFileStructure(); pTemp.RootFolder = strFolder; pTemp.ProjectExcel = Path.Combine(strFolder, ProjectExcel); if (!File.Exists(pTemp.ProjectExcel)) { errMsg = "项目信息文件(Project.xls)不存在"; return false; } pTemp.FlyFile = Path.Combine(strFolder, FlyFile); if (!File.Exists(pTemp.FlyFile)) { errMsg = "项目Fly文件不存在"; return false; } pTemp.ImageFile = Path.Combine(strFolder, ImageFile); //if (!File.Exists(pTemp.ImageFile)) //{ // errMsg = "项目影像文件不存在"; // return false; //} pTemp.DemFile = Path.Combine(strFolder, ImageFile); //if (!File.Exists(pTemp.DemFile)) //{ // errMsg = "项目高程文件不存在"; // return false; //} string[] schemaFolders = Directory.GetDirectories(strFolder); if (strFolder == null || strFolder.Length == 0) { errMsg = "没有方案"; return false; } List<SchemaFileStructure> sListTemp = new List<SchemaFileStructure>(); foreach (string schemaFolder in schemaFolders) { SchemaFileStructure sTemp = new SchemaFileStructure(); sTemp.SchemaFolder = schemaFolder; sTemp.SchemaExcel = Path.Combine(schemaFolder, SchemaExcel); if (!File.Exists(sTemp.SchemaExcel)) continue; sTemp.LocationExcel = Path.Combine(schemaFolder, LocationExcel); if (!File.Exists(sTemp.LocationExcel)) continue; sTemp.ModelFolder = Path.Combine(schemaFolder, ModelFolder); if (!Directory.Exists(sTemp.ModelFolder)) continue; sListTemp.Add(sTemp); } if (sListTemp.Count == 0) { errMsg = "当前文件夹下没有方案"; return false; } pTemp.SchemaStruactures = sListTemp; pFileStructure = pTemp; return true; }
public static bool ImportProject(ProjectFileStructure pFileStructure,ref ProjectInfo projectInfo) { if (pFileStructure == null) return false; if (projectInfo == null) projectInfo = new ProjectInfo(); try { projectInfo.Folder = Path.Combine(m_WorkFolder, Guid.NewGuid().ToString());// pFileStructure.RootFolder; Directory.CreateDirectory(projectInfo.Folder); projectInfo.File = Path.Combine(projectInfo.Folder, FlyFile); File.Copy(pFileStructure.FlyFile, projectInfo.File); DataTable dtProejct = ExcelHelper.ReadData(pFileStructure.ProjectExcel); if (dtProejct != null && dtProejct.Rows.Count > 0) { projectInfo.Name = dtProejct.Rows[0][0] as string; projectInfo.Type = dtProejct.Rows[0][1] as string; projectInfo.Enterprise = dtProejct.Rows[0][2] as string; projectInfo.Address = dtProejct.Rows[0][3] as string; } List<SchemaInfo> schemaList = new List<SchemaInfo>(); foreach (SchemaFileStructure schemaStructure in pFileStructure.SchemaStruactures) { SchemaInfo schemaInfo = new SchemaInfo(); schemaInfo.Folder = System.IO.Path.Combine(projectInfo.Folder, System.IO.Path.GetFileName(schemaStructure.SchemaFolder)); schemaInfo.File = Path.Combine(schemaInfo.Folder, BuildingShp); DataTable dtSchema = ExcelHelper.ReadData(schemaStructure.SchemaExcel); if (dtSchema != null && dtSchema.Rows.Count > 0) { schemaInfo.Name = dtSchema.Rows[0][0] as string; schemaInfo.Type = dtSchema.Rows[0][1] as string; schemaInfo.BuildingArea = Convert.ToDouble(dtSchema.Rows[0][2]); schemaInfo.VegetationArea = Convert.ToDouble(dtSchema.Rows[0][3]); schemaInfo.RoadArea = Convert.ToDouble(dtSchema.Rows[0][4]); } schemaInfo.Project = projectInfo; Directory.CreateDirectory(schemaInfo.Folder); // 方案文件夹 string modelFolder = Path.Combine(schemaInfo.Folder, ModelFolder); // 模型文件夹 Directory.CreateDirectory(modelFolder); string[] modelFiles = Directory.GetFiles(schemaStructure.ModelFolder);// 模型 foreach (string strFile in modelFiles) { File.Copy(strFile, Path.Combine(modelFolder, Path.GetFileName(strFile))); } //schemaStructure.LocationExcel //File.Copy(m_LocationTemplateShp+".shp",schemaInfo.File); // shp //CopyShp(Path.Combine(schemaStructure.SchemaFolder, BuildingShp), Path.Combine(schemaInfo.Folder, BuildingShp)); //CopyShp(Path.Combine(schemaStructure.SchemaFolder, "Building"), schemaInfo.Folder,"Building"); CopyShp(Path.Combine(schemaStructure.SchemaFolder, "Building"), Path.Combine(schemaInfo.Folder, "Building")); // ESRI.ArcGIS.Geodatabase schemaList.Add(schemaInfo); } projectInfo.Schemas = schemaList; // 记录 AddProjectInfo(projectInfo); } catch { return false; } return true; }