using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Base; using Eplan.EplApi.DataModel; using Eplan.EplApi.HEServices; using KPlan.RefActions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using KPlan.Util; namespace KPlan.Actions { class CheckProjectAction : Eplan.EplApi.ApplicationFramework.IEplAction { private String projectCode = string.Empty; private String PROJ_NAME = string.Empty; //Project's property which return Name of Project - project name only without path. private String PROJ_FULL_NAME = string.Empty;//string : project's full name for example "C:\EPLANPROJECTSDEMO2_D" public bool Execute(ActionCallingContext ctx) { if (!Util.TCUtil.CheckLogin()) { return true; } try { SelectionSet selectionSet = new SelectionSet(); Project currentProject = selectionSet.GetCurrentProject(false); if (currentProject == null) { MessageBox.Show("项目不存在!", "提示"); return true; } projectCode = EplanUtil.GetPropValue(currentProject.Properties.PROJ_DRAWINGNUMBER); if (projectCode == String.Empty) { MessageBox.Show("项目编号不能为空!", "提示"); return true; } string prjPath = currentProject.ProjectDirectoryPath; // MessageBox.Show("prjPath--------------" + prjPath, "提示"); DirectoryInfo di = new DirectoryInfo(prjPath); prjPath = di.Parent.FullName; //MessageBox.Show("prjPath2--------------" + prjPath, "提示"); if (!prjPath.EndsWith("\\")) { prjPath += "\\"; } // MessageBox.Show("prjPath3--------------" + prjPath, "提示"); //项目打包并生成Xml if (ExportXml(currentProject, prjPath)) { //MessageBox.Show("打包--------------" , "提示"); CheckForm checkForm = new CheckForm(); checkForm.projectCode = projectCode; checkForm.currentProject = currentProject; checkForm.xmlFilePath = prjPath + currentProject.ProjectName + ".xml"; checkForm.ShowDialog(); if (TCTool.deleteXML.Equals("TRUE", StringComparison.OrdinalIgnoreCase)) { File.Delete(prjPath + currentProject.ProjectName + ".xml"); } } } catch (System.Exception ex) { Util.KUtil.LogErr(ex); MessageBox.Show("执行出错:" + ex.Message); } return true; } public bool OnRegister(ref string Name, ref int Ordinal) { Name = "CheckProjectAction"; Ordinal = 20; return true; } public void GetActionProperties(ref ActionProperties actionProperties) { //actionProperties.Description = "Action test with parameters."; } private bool ExportXml(Project currentProject, string exportPath) { Progress progress = new Progress("SimpleProgress"); try { progress.SetTitle("检查项目..."); progress.SetAllowCancel(true); progress.BeginPart(100.0, ""); //progress.ShowImmediately(); PROJ_FULL_NAME = currentProject.ProjectFullName; PROJ_NAME = currentProject.ProjectName; string xmlFilePath = exportPath + PROJ_NAME + ".xml"; KUtil.Log("导出Partlist:"+xmlFilePath); PartsService ps = new PartsService(); ps.ExportPartsList(currentProject, xmlFilePath, PartsService.Format.XML); if (progress.Canceled()) { progress.EndPart(true); return false; } progress.EndPart(true); } catch(System.Exception ex) { KUtil.LogErr(ex); progress.EndPart(true); MessageBox.Show("导出xml信息失败!"); return false; } return true; } private bool ExportXml_old(Project currentProject, string exportPath) { //MessageBox.Show("开始导出xml信息!"); bool result = true; try { PROJ_FULL_NAME = currentProject.ProjectFullName; PROJ_NAME = currentProject.ProjectName; string elkName = PROJ_FULL_NAME + ".elk"; string xmlFilePath = exportPath + PROJ_NAME + ".xml"; // MessageBox.Show("xmlFilePath------------------" + xmlFilePath); ActionCallingContext context_temp = new ActionCallingContext(); context_temp.AddParameter("TYPE", "EXPORT"); context_temp.AddParameter("PROJECTNAME", elkName); context_temp.AddParameter("EXPORTFILE", xmlFilePath); //context_temp.AddParameter("FORMAT", "XPalXmlExporter"); context_temp.AddParameter("MODE", "0"); context_temp.AddParameter("ADDITIONAL_LANGUAGE", "1"); Progress progress = new Progress("SimpleProgress"); progress.SetActionText("检查"); progress.BeginPart(100.0, ""); progress.ShowImmediately(); progress.SetAllowCancel(true); if (!progress.Canceled()) { CommandLineInterpreter commandLineInterpreter = new CommandLineInterpreter(); if (!Util.KUtil.FileIsUsed(xmlFilePath)) { if (!commandLineInterpreter.Execute("partslist", context_temp)) { MessageBox.Show("导出xml信息失败!"); result = false; progress.EndPart(true); return result; } } progress.EndPart(); } progress.EndPart(true); } catch (Exception ex) { MessageBox.Show("Error:" + ex.Message); result = false; } return result; } } }