|
|
using Eplan.EplApi.ApplicationFramework;
|
|
|
using Eplan.EplApi.Base;
|
|
|
using Eplan.EplApi.DataModel;
|
|
|
using Eplan.EplApi.HEServices;
|
|
|
using KPlan.RefActions;
|
|
|
using KPlan.Util;
|
|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Xml;
|
|
|
|
|
|
namespace KPlan.Actions {
|
|
|
class SaveProjectAction : 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 {
|
|
|
TCTool.ReadConfigs();
|
|
|
|
|
|
SelectionSet selectionSet = new SelectionSet();
|
|
|
Project currentProject = selectionSet.GetCurrentProject(false);
|
|
|
if (currentProject == null) {
|
|
|
MessageBox.Show("项目不存在11!", "提示");
|
|
|
return true;
|
|
|
}
|
|
|
projectCode = EplanUtil.GetProjectCode(currentProject);
|
|
|
if (projectCode == String.Empty) {
|
|
|
MessageBox.Show("项目编号不能为空!", "提示");
|
|
|
return true;
|
|
|
}
|
|
|
string prjPath = currentProject.ProjectDirectoryPath;
|
|
|
DirectoryInfo di = new DirectoryInfo(prjPath);
|
|
|
prjPath = di.Parent.FullName;
|
|
|
if (!prjPath.EndsWith("\\")) {
|
|
|
prjPath += "\\";
|
|
|
}
|
|
|
|
|
|
Dictionary<string, string> nameToPaths = new Dictionary<string, string>();
|
|
|
if (ZipProjectAndExport(currentProject, prjPath, nameToPaths)) {
|
|
|
KUtil.Log(prjPath);
|
|
|
SaveForm saveForm = new SaveForm();
|
|
|
saveForm.projectCode = projectCode;
|
|
|
saveForm.currentProject = currentProject;
|
|
|
saveForm.xmlFilePath = prjPath + currentProject.ProjectName + ".xml";
|
|
|
saveForm.nameToPaths = nameToPaths;
|
|
|
saveForm.ShowDialog();
|
|
|
|
|
|
if (TCTool.deleteXML.Equals("TRUE", StringComparison.OrdinalIgnoreCase)) {
|
|
|
File.Delete(prjPath + currentProject.ProjectName + ".xml");
|
|
|
}
|
|
|
Dictionary<string, string>.KeyCollection kc = nameToPaths.Keys;
|
|
|
foreach (string name in kc) {
|
|
|
File.Delete(nameToPaths[name]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (System.Exception ex) {
|
|
|
KUtil.LogErr(ex);
|
|
|
MessageBox.Show("执行出错:" + ex.Message);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
public bool OnRegister(ref string Name, ref int Ordinal) {
|
|
|
Name = "SaveProjectAction";
|
|
|
Ordinal = 20;
|
|
|
return true;
|
|
|
}
|
|
|
public void GetActionProperties(ref ActionProperties actionProperties) {
|
|
|
//actionProperties.Description = "Action test with parameters.";
|
|
|
}
|
|
|
|
|
|
private bool ZipProjectAndExport(Project currentProject, string exportPath, Dictionary<string, string> nameToPaths) {
|
|
|
bool result = true;
|
|
|
Progress progress = new Progress("SimpleProgress");
|
|
|
try {
|
|
|
PROJ_FULL_NAME = currentProject.ProjectFullName;
|
|
|
PROJ_NAME = currentProject.ProjectName;
|
|
|
string elkName = PROJ_FULL_NAME + ".elk";
|
|
|
string zipName = PROJ_NAME + ".zw1";
|
|
|
string pdfName = exportPath + PROJ_NAME + ".pdf";
|
|
|
string xmlFilePath = exportPath + PROJ_NAME + ".xml";
|
|
|
KUtil.Log(xmlFilePath);
|
|
|
|
|
|
progress.BeginPart(100.0, "");
|
|
|
progress.ShowImmediately();
|
|
|
progress.SetAllowCancel(true);
|
|
|
// MessageBox.Show("progress----------------1" );
|
|
|
if (!progress.Canceled()) {
|
|
|
// MessageBox.Show("progress----------------2");
|
|
|
File.Delete(zipName);
|
|
|
// MessageBox.Show("progress----------------3");
|
|
|
if (File.Exists(zipName)) {
|
|
|
MessageBox.Show("项目不能备份1!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
KUtil.Log("备份项目:"+elkName+" -> "+exportPath+"|"+zipName);
|
|
|
Backup backup = new Backup();
|
|
|
backup.Project(elkName, "", exportPath, zipName, Backup.Type.MakeBackup, Backup.Medium.Disk, 0.0, Backup.Amount.All, false, true, true, false);
|
|
|
|
|
|
nameToPaths.Add("ZW1", exportPath + zipName);
|
|
|
if (!KUtil.FileIsUsed(xmlFilePath)) {
|
|
|
File.Delete(xmlFilePath);
|
|
|
if (File.Exists(xmlFilePath)) {
|
|
|
MessageBox.Show("导出xml信息失败1!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
PartsService ps = new PartsService();
|
|
|
ps.ExportPartsList(currentProject, xmlFilePath, PartsService.Format.XML);
|
|
|
}
|
|
|
bool readResult = ReadXMLFile(xmlFilePath);
|
|
|
//MessageBox.Show("progress----------------8");
|
|
|
if (readResult) {
|
|
|
//MessageBox.Show("progress----------------9");
|
|
|
File.Delete(pdfName);
|
|
|
//MessageBox.Show("progress----------------10");
|
|
|
if (File.Exists(pdfName)) {
|
|
|
MessageBox.Show("导出PDF失败1!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
Export export = new Export();
|
|
|
//MessageBox.Show("progress----------------11");
|
|
|
export.PdfProject(currentProject, "", pdfName, Export.DegreeOfColor.BlackAndWhite, true, "", true);
|
|
|
// MessageBox.Show("progress----------------12");
|
|
|
if (!File.Exists(pdfName)) {
|
|
|
MessageBox.Show("导出PDF失败2!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
KUtil.Log(pdfName);
|
|
|
// MessageBox.Show("progress----------------13");
|
|
|
if (!nameToPaths.ContainsKey(PROJ_NAME)) {
|
|
|
nameToPaths.Add(PROJ_NAME, pdfName);
|
|
|
}
|
|
|
// MessageBox.Show("progress----------------14");
|
|
|
Page[] pages = currentProject.Pages;
|
|
|
int pageNum = pages.Length;
|
|
|
StringBuilder invalidCharSB = new StringBuilder("");
|
|
|
for (int i = 0; i < pageNum; i++) {
|
|
|
string pageName = pages[i].Name;
|
|
|
if (!pageName.StartsWith("&")) {
|
|
|
string plant = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_PLANT.IsEmpty) {
|
|
|
plant = pages[i].Properties.get_DESIGNATION_FULLPLANT(0);
|
|
|
}
|
|
|
string plant_descr = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_PLANT_DESCR.IsEmpty) {
|
|
|
plant_descr = pages[i].Properties.DESIGNATION_PLANT_DESCR.ToString(EplanUtil.Language_CN);
|
|
|
}
|
|
|
string userDefiend = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_USERDEFINED.IsEmpty) {
|
|
|
userDefiend = pages[i].Properties.get_DESIGNATION_FULLUSERDEFINED(0);
|
|
|
}
|
|
|
string plantFullName = plant + " " + plant_descr;
|
|
|
if (plantFullName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) {
|
|
|
if (!invalidCharSB.ToString().Contains(plantFullName)) {
|
|
|
invalidCharSB.Append(plantFullName).Append(",");
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
//string pagePdfName = exportPath + plantFullName + ".pdf";
|
|
|
ArrayList listPlant = new ArrayList();
|
|
|
ArrayList listCnLocation = new ArrayList();
|
|
|
ArrayList listCtLocation = new ArrayList();
|
|
|
ArrayList listPreLocation = new ArrayList();
|
|
|
StringBuilder cadPathSB = new StringBuilder("");
|
|
|
//bool isDocument = false;
|
|
|
//if (!pages[i].Properties.PAGE_EXTDOCUMENT.IsEmpty)
|
|
|
//{
|
|
|
// string docName = pages[i].Properties.PAGE_EXTDOCUMENT.ToString().Trim();
|
|
|
// if (!docName.Equals(""))
|
|
|
// {
|
|
|
// isDocument = true;
|
|
|
// if (docName.EndsWith(".dwg"))
|
|
|
// {
|
|
|
// string cadPath = docName.Replace("$(DOC)",
|
|
|
// currentProject.ProjectDirectoryPath +
|
|
|
// "\\DOC");
|
|
|
// if (File.Exists(cadPath))
|
|
|
// {
|
|
|
// cadPathSB.Append(cadPath + ";");
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//if (!isDocument)
|
|
|
//{
|
|
|
listPlant.Add(pages[i]);
|
|
|
//}
|
|
|
string location = "";
|
|
|
string cnPdfName = "";
|
|
|
string ctPdfName = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_LOCATION.IsEmpty) {
|
|
|
location = pages[i].Properties.DESIGNATION_LOCATION.ToString();
|
|
|
if (location.Equals("CN")) {
|
|
|
string locationDescr = pages[i].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
listCnLocation.Add(pages[i]);
|
|
|
//cnPdfName = exportPath + plantFullName + "+" + location + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
else if (location.Equals("CT")) {
|
|
|
string locationDescr = pages[i].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
listCtLocation.Add(pages[i]);
|
|
|
//ctPdfName = exportPath + plantFullName + "+" + location + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
else {
|
|
|
listPreLocation.Add(pages[i]);
|
|
|
}
|
|
|
}
|
|
|
//export.DxfDwgPageToDisk(pages[i], "", exportPath, pages[i].Properties.PAGE_FULLNAME.ToString().Replace("/", "&"));
|
|
|
for (int j = (i + 1); j < pageNum; j++) {
|
|
|
string nextPageName = pages[j].Name;
|
|
|
|
|
|
//bool isDocument2 = false;
|
|
|
//if (!pages[j].Properties.PAGE_EXTDOCUMENT.IsEmpty)
|
|
|
//{
|
|
|
// string docName = pages[j].Properties.PAGE_EXTDOCUMENT.ToString().Trim();
|
|
|
// if (!docName.Equals(""))
|
|
|
// {
|
|
|
// isDocument2 = true;
|
|
|
// if (docName.EndsWith(".dwg"))
|
|
|
// {
|
|
|
// string cadPath = docName.Replace("$(DOC)", currentProject.ProjectDirectoryPath + "\\DOC");
|
|
|
// if (File.Exists(cadPath))
|
|
|
// {
|
|
|
// cadPathSB.Append(cadPath + ";");
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
string nextPlant = "";
|
|
|
if (!pages[j].Properties.DESIGNATION_PLANT.IsEmpty) {
|
|
|
nextPlant = pages[j].Properties.get_DESIGNATION_FULLPLANT(0);
|
|
|
}
|
|
|
if (!nextPageName.StartsWith("&") && nextPlant.Equals(plant)) {
|
|
|
//export.DxfDwgPageToDisk(pages[j], "", exportPath, pages[j].Properties.PAGE_FULLNAME.ToString().Replace("/", "&"));
|
|
|
if (!pages[j].Properties.DESIGNATION_LOCATION.IsEmpty) {
|
|
|
string nextLocation = pages[j].Properties.DESIGNATION_LOCATION.ToString();
|
|
|
if (nextLocation.Equals("CN")) {
|
|
|
listCnLocation.Add(pages[j]);
|
|
|
if (cnPdfName.Equals("")) {
|
|
|
string locationDescr = pages[j].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
//cnPdfName = exportPath + plantFullName + "+" + nextLocation + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
}
|
|
|
else if (nextLocation.Equals("CT")) {
|
|
|
listCtLocation.Add(pages[j]);
|
|
|
if (ctPdfName.Equals("")) {
|
|
|
string locationDescr = pages[j].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
//ctPdfName = exportPath + plantFullName + "+" + nextLocation + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
listPreLocation.Add(pages[j]);
|
|
|
}
|
|
|
}
|
|
|
//if (!isDocument2)
|
|
|
//{
|
|
|
listPlant.Add(pages[j]);
|
|
|
//}
|
|
|
i++;
|
|
|
}
|
|
|
else {
|
|
|
//export.DxfDwgPageToDisk(pages[j], "", exportPath, pages[j].Properties.PAGE_FULLNAME.ToString().Replace("/", "&"));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
StringBuilder pdfPathSB = new StringBuilder("");
|
|
|
if (listCnLocation.Count > 0) {
|
|
|
File.Delete(cnPdfName);
|
|
|
//export.PdfPages(listCnLocation, "", cnPdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
//pdfPathSB.Append(cnPdfName).Append(";");
|
|
|
}
|
|
|
if (listCtLocation.Count > 0) {
|
|
|
File.Delete(cnPdfName);
|
|
|
//export.PdfPages(listCtLocation, "", ctPdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
//pdfPathSB.Append(ctPdfName).Append(";");
|
|
|
}
|
|
|
if (!nameToPaths.ContainsKey(plantFullName)) {
|
|
|
if (pdfPathSB.ToString().Equals("")) {
|
|
|
if (listPlant.Count > 0) {
|
|
|
//File.Delete(pagePdfName);
|
|
|
//export.PdfPages(listPlant, "", pagePdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
}
|
|
|
//MessageBox.Show("plantFullName=" + plantFullName + ",pagePdfName=" + pagePdfName);
|
|
|
//nameToPaths.Add(plantFullName, pagePdfName);
|
|
|
}
|
|
|
else {
|
|
|
if (listPreLocation.Count > 0) {
|
|
|
//File.Delete(pagePdfName);
|
|
|
//export.PdfPages(listPlant, "", pagePdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
//pdfPathSB.Append(pagePdfName).Append(";");
|
|
|
}
|
|
|
//MessageBox.Show("plantFullName=" + plantFullName + ",pagePdfName=" + pdfPathSB.ToString());
|
|
|
//nameToPaths.Add(plantFullName, pdfPathSB.ToString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (!invalidCharSB.ToString().Equals("")) {
|
|
|
MessageBox.Show("高层" + invalidCharSB.ToString().Substring(0, invalidCharSB.ToString().Length - 1) + "含有非法字符,请修改后再保存!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
if (!File.Exists(pdfName)) {
|
|
|
MessageBox.Show("导出PDF失败!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
progress.EndPart();
|
|
|
}
|
|
|
progress.EndPart(true);
|
|
|
}
|
|
|
catch (Exception ex) {
|
|
|
KUtil.LogErr(ex);
|
|
|
MessageBox.Show("Error!!!" + ex.Message);
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private bool ZipProjectAndExport_old(Project currentProject, string exportPath, Dictionary<string, string> nameToPaths) {
|
|
|
bool result = true;
|
|
|
try {
|
|
|
PROJ_FULL_NAME = currentProject.ProjectFullName;
|
|
|
PROJ_NAME = currentProject.ProjectName;
|
|
|
|
|
|
string elkName = PROJ_FULL_NAME + ".elk";
|
|
|
string zipName = PROJ_NAME + ".zw1";
|
|
|
string pdfName = exportPath + PROJ_NAME + ".pdf";
|
|
|
// MessageBox.Show("pdfName----------------" + pdfName);
|
|
|
ActionCallingContext actionCallingContext_zw1 = new ActionCallingContext();
|
|
|
actionCallingContext_zw1.AddParameter("TYPE", "PROJECT");
|
|
|
actionCallingContext_zw1.AddParameter("PROJECTNAME", elkName);
|
|
|
actionCallingContext_zw1.AddParameter("DESTINATIONPATH", exportPath);
|
|
|
actionCallingContext_zw1.AddParameter("ARCHIVENAME", zipName);
|
|
|
actionCallingContext_zw1.AddParameter("BACKUPMETHOD", "BACKUP");
|
|
|
actionCallingContext_zw1.AddParameter("BACKUPMEDIA", "DISK");
|
|
|
actionCallingContext_zw1.AddParameter("SPLITSIZE", "0.0");
|
|
|
actionCallingContext_zw1.AddParameter("BACKUPAMOUNT", "BACKUPAMOUNT_ALL");
|
|
|
actionCallingContext_zw1.AddParameter("COMPRESSPRJ", "0");
|
|
|
actionCallingContext_zw1.AddParameter("INCLEXTDOCS", "1");
|
|
|
actionCallingContext_zw1.AddParameter("INCLIMAGES", "1");
|
|
|
// MessageBox.Show("pdfName1----------------" + pdfName);
|
|
|
//=============通过项目生成PART_LIST,导出PART_LIST的CSV文件======
|
|
|
string partListPath = currentProject.ProjectDirectoryPath;//string : project's directory path for example "C:\EPLANPROJECTSDEMO2_D.EDB"
|
|
|
//================通过项目导出PART_LIST的XML文件
|
|
|
|
|
|
string xmlFilePath = exportPath + PROJ_NAME + ".xml";
|
|
|
// MessageBox.Show("pdfName2----------------" + pdfName);
|
|
|
// MessageBox.Show("导出xml3");
|
|
|
ActionCallingContext actionCallingContext_xml = new ActionCallingContext();
|
|
|
actionCallingContext_xml.AddParameter("TYPE", "EXPORT");
|
|
|
actionCallingContext_xml.AddParameter("PROJECTNAME", elkName);
|
|
|
actionCallingContext_xml.AddParameter("EXPORTFILE", xmlFilePath);
|
|
|
//context_temp.AddParameter("FORMAT", "XPalXmlExporter");
|
|
|
actionCallingContext_xml.AddParameter("MODE", "0");
|
|
|
actionCallingContext_xml.AddParameter("ADDITIONAL_LANGUAGE", "1");
|
|
|
KUtil.Log(xmlFilePath);
|
|
|
Progress progress = new Progress("SimpleProgress");
|
|
|
progress.BeginPart(100.0, "");
|
|
|
progress.ShowImmediately();
|
|
|
progress.SetAllowCancel(true);
|
|
|
// MessageBox.Show("progress----------------1" );
|
|
|
if (!progress.Canceled()) {
|
|
|
// MessageBox.Show("progress----------------2");
|
|
|
File.Delete(zipName);
|
|
|
// MessageBox.Show("progress----------------3");
|
|
|
if (File.Exists(zipName)) {
|
|
|
MessageBox.Show("项目不能备份1!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
CommandLineInterpreter commandLineInterpreter = new CommandLineInterpreter();
|
|
|
if (!commandLineInterpreter.Execute("backup", actionCallingContext_zw1)) {
|
|
|
MessageBox.Show("项目不能备份2!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
nameToPaths.Add("ZW1", exportPath + zipName);
|
|
|
if (!KUtil.FileIsUsed(xmlFilePath)) {
|
|
|
File.Delete(xmlFilePath);
|
|
|
if (File.Exists(xmlFilePath)) {
|
|
|
MessageBox.Show("导出xml信息失败1!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
//MessageBox.Show("progress----------------4");
|
|
|
if (!commandLineInterpreter.Execute("partslist", actionCallingContext_xml)) {
|
|
|
|
|
|
MessageBox.Show("导出xml信息失败2!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
// MessageBox.Show("progress----------------5");
|
|
|
}
|
|
|
bool readResult = ReadXMLFile(xmlFilePath);
|
|
|
//MessageBox.Show("progress----------------8");
|
|
|
if (readResult) {
|
|
|
//MessageBox.Show("progress----------------9");
|
|
|
File.Delete(pdfName);
|
|
|
//MessageBox.Show("progress----------------10");
|
|
|
if (File.Exists(pdfName)) {
|
|
|
MessageBox.Show("导出PDF失败1!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
Export export = new Export();
|
|
|
//MessageBox.Show("progress----------------11");
|
|
|
export.PdfProject(currentProject, "", pdfName, Export.DegreeOfColor.BlackAndWhite, true, "", true);
|
|
|
// MessageBox.Show("progress----------------12");
|
|
|
if (!File.Exists(pdfName)) {
|
|
|
MessageBox.Show("导出PDF失败2!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
KUtil.Log(pdfName);
|
|
|
// MessageBox.Show("progress----------------13");
|
|
|
if (!nameToPaths.ContainsKey(PROJ_NAME)) {
|
|
|
nameToPaths.Add(PROJ_NAME, pdfName);
|
|
|
}
|
|
|
// MessageBox.Show("progress----------------14");
|
|
|
Page[] pages = currentProject.Pages;
|
|
|
int pageNum = pages.Length;
|
|
|
StringBuilder invalidCharSB = new StringBuilder("");
|
|
|
for (int i = 0; i < pageNum; i++) {
|
|
|
string pageName = pages[i].Name;
|
|
|
if (!pageName.StartsWith("&")) {
|
|
|
string plant = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_PLANT.IsEmpty) {
|
|
|
plant = pages[i].Properties.get_DESIGNATION_FULLPLANT(0);
|
|
|
}
|
|
|
string plant_descr = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_PLANT_DESCR.IsEmpty) {
|
|
|
plant_descr = pages[i].Properties.DESIGNATION_PLANT_DESCR.ToString(EplanUtil.Language_CN);
|
|
|
}
|
|
|
string userDefiend = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_USERDEFINED.IsEmpty) {
|
|
|
userDefiend = pages[i].Properties.get_DESIGNATION_FULLUSERDEFINED(0);
|
|
|
}
|
|
|
string plantFullName = plant + " " + plant_descr;
|
|
|
if (plantFullName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) {
|
|
|
if (!invalidCharSB.ToString().Contains(plantFullName)) {
|
|
|
invalidCharSB.Append(plantFullName).Append(",");
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
//string pagePdfName = exportPath + plantFullName + ".pdf";
|
|
|
ArrayList listPlant = new ArrayList();
|
|
|
ArrayList listCnLocation = new ArrayList();
|
|
|
ArrayList listCtLocation = new ArrayList();
|
|
|
ArrayList listPreLocation = new ArrayList();
|
|
|
StringBuilder cadPathSB = new StringBuilder("");
|
|
|
//bool isDocument = false;
|
|
|
//if (!pages[i].Properties.PAGE_EXTDOCUMENT.IsEmpty)
|
|
|
//{
|
|
|
// string docName = pages[i].Properties.PAGE_EXTDOCUMENT.ToString().Trim();
|
|
|
// if (!docName.Equals(""))
|
|
|
// {
|
|
|
// isDocument = true;
|
|
|
// if (docName.EndsWith(".dwg"))
|
|
|
// {
|
|
|
// string cadPath = docName.Replace("$(DOC)",
|
|
|
// currentProject.ProjectDirectoryPath +
|
|
|
// "\\DOC");
|
|
|
// if (File.Exists(cadPath))
|
|
|
// {
|
|
|
// cadPathSB.Append(cadPath + ";");
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//if (!isDocument)
|
|
|
//{
|
|
|
listPlant.Add(pages[i]);
|
|
|
//}
|
|
|
string location = "";
|
|
|
string cnPdfName = "";
|
|
|
string ctPdfName = "";
|
|
|
if (!pages[i].Properties.DESIGNATION_LOCATION.IsEmpty) {
|
|
|
location = pages[i].Properties.DESIGNATION_LOCATION.ToString();
|
|
|
if (location.Equals("CN")) {
|
|
|
string locationDescr = pages[i].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
listCnLocation.Add(pages[i]);
|
|
|
//cnPdfName = exportPath + plantFullName + "+" + location + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
else if (location.Equals("CT")) {
|
|
|
string locationDescr = pages[i].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
listCtLocation.Add(pages[i]);
|
|
|
//ctPdfName = exportPath + plantFullName + "+" + location + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
else {
|
|
|
listPreLocation.Add(pages[i]);
|
|
|
}
|
|
|
}
|
|
|
//export.DxfDwgPageToDisk(pages[i], "", exportPath, pages[i].Properties.PAGE_FULLNAME.ToString().Replace("/", "&"));
|
|
|
for (int j = (i + 1); j < pageNum; j++) {
|
|
|
string nextPageName = pages[j].Name;
|
|
|
|
|
|
//bool isDocument2 = false;
|
|
|
//if (!pages[j].Properties.PAGE_EXTDOCUMENT.IsEmpty)
|
|
|
//{
|
|
|
// string docName = pages[j].Properties.PAGE_EXTDOCUMENT.ToString().Trim();
|
|
|
// if (!docName.Equals(""))
|
|
|
// {
|
|
|
// isDocument2 = true;
|
|
|
// if (docName.EndsWith(".dwg"))
|
|
|
// {
|
|
|
// string cadPath = docName.Replace("$(DOC)", currentProject.ProjectDirectoryPath + "\\DOC");
|
|
|
// if (File.Exists(cadPath))
|
|
|
// {
|
|
|
// cadPathSB.Append(cadPath + ";");
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
string nextPlant = "";
|
|
|
if (!pages[j].Properties.DESIGNATION_PLANT.IsEmpty) {
|
|
|
nextPlant = pages[j].Properties.get_DESIGNATION_FULLPLANT(0);
|
|
|
}
|
|
|
if (!nextPageName.StartsWith("&") && nextPlant.Equals(plant)) {
|
|
|
//export.DxfDwgPageToDisk(pages[j], "", exportPath, pages[j].Properties.PAGE_FULLNAME.ToString().Replace("/", "&"));
|
|
|
if (!pages[j].Properties.DESIGNATION_LOCATION.IsEmpty) {
|
|
|
string nextLocation = pages[j].Properties.DESIGNATION_LOCATION.ToString();
|
|
|
if (nextLocation.Equals("CN")) {
|
|
|
listCnLocation.Add(pages[j]);
|
|
|
if (cnPdfName.Equals("")) {
|
|
|
string locationDescr = pages[j].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
//cnPdfName = exportPath + plantFullName + "+" + nextLocation + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
}
|
|
|
else if (nextLocation.Equals("CT")) {
|
|
|
listCtLocation.Add(pages[j]);
|
|
|
if (ctPdfName.Equals("")) {
|
|
|
string locationDescr = pages[j].Properties.DESIGNATION_LOCATION_DESCR.ToString();
|
|
|
//ctPdfName = exportPath + plantFullName + "+" + nextLocation + " " + TcTool.getCNString(locationDescr) + ".pdf";
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
listPreLocation.Add(pages[j]);
|
|
|
}
|
|
|
}
|
|
|
//if (!isDocument2)
|
|
|
//{
|
|
|
listPlant.Add(pages[j]);
|
|
|
//}
|
|
|
i++;
|
|
|
}
|
|
|
else {
|
|
|
//export.DxfDwgPageToDisk(pages[j], "", exportPath, pages[j].Properties.PAGE_FULLNAME.ToString().Replace("/", "&"));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
StringBuilder pdfPathSB = new StringBuilder("");
|
|
|
if (listCnLocation.Count > 0) {
|
|
|
File.Delete(cnPdfName);
|
|
|
//export.PdfPages(listCnLocation, "", cnPdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
//pdfPathSB.Append(cnPdfName).Append(";");
|
|
|
}
|
|
|
if (listCtLocation.Count > 0) {
|
|
|
File.Delete(cnPdfName);
|
|
|
//export.PdfPages(listCtLocation, "", ctPdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
//pdfPathSB.Append(ctPdfName).Append(";");
|
|
|
}
|
|
|
if (!nameToPaths.ContainsKey(plantFullName)) {
|
|
|
if (pdfPathSB.ToString().Equals("")) {
|
|
|
if (listPlant.Count > 0) {
|
|
|
//File.Delete(pagePdfName);
|
|
|
//export.PdfPages(listPlant, "", pagePdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
}
|
|
|
//MessageBox.Show("plantFullName=" + plantFullName + ",pagePdfName=" + pagePdfName);
|
|
|
//nameToPaths.Add(plantFullName, pagePdfName);
|
|
|
}
|
|
|
else {
|
|
|
if (listPreLocation.Count > 0) {
|
|
|
//File.Delete(pagePdfName);
|
|
|
//export.PdfPages(listPlant, "", pagePdfName, Export.DegreeOfColor.Color, true, "", true);
|
|
|
//pdfPathSB.Append(pagePdfName).Append(";");
|
|
|
}
|
|
|
//MessageBox.Show("plantFullName=" + plantFullName + ",pagePdfName=" + pdfPathSB.ToString());
|
|
|
//nameToPaths.Add(plantFullName, pdfPathSB.ToString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (!invalidCharSB.ToString().Equals("")) {
|
|
|
MessageBox.Show("高层" + invalidCharSB.ToString().Substring(0, invalidCharSB.ToString().Length - 1) + "含有非法字符,请修改后再保存!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
if (!File.Exists(pdfName)) {
|
|
|
MessageBox.Show("导出PDF失败!");
|
|
|
result = false;
|
|
|
progress.EndPart(true);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
progress.EndPart();
|
|
|
}
|
|
|
progress.EndPart(true);
|
|
|
}
|
|
|
catch (Exception ex) {
|
|
|
MessageBox.Show("Error!!!" + ex.Message);
|
|
|
result = false;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public bool ReadXMLFile(String url) {
|
|
|
//MessageBox.Show("progress----------------7");
|
|
|
XmlTextReader xtr = new XmlTextReader(url);
|
|
|
try {
|
|
|
while (xtr.Read()) {
|
|
|
|
|
|
if (xtr.NodeType == XmlNodeType.Element) {
|
|
|
String element_name = xtr.Name;
|
|
|
if (xtr.HasAttributes) {
|
|
|
if (element_name == "part") {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
xtr.Close();
|
|
|
}
|
|
|
catch (XmlException ex) {
|
|
|
MessageBox.Show(ex.Message);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|