using System.Windows.Forms; using Eplan.EplApi.ApplicationFramework; using Eplan.EplApi.Scripting; using Eplan.EplApi.Base; using System.Threading; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Xml; using System; using System.Diagnostics; public class FrmMain : System.Windows.Forms.Form { //////////////////////////////////////////////////////////////////////// // Globale Variablen //public int iType; public int[] iType; public string indexLang; public string indexRev; public string strLanguage; public string strOrder; public string PDFExportPath = @"F:\Temp\Teichert\Projekte\$(PROJECTNAME)\"; public string PDFExportPath1 = @"F:\Temp\Teichert\Projekte\"; public string XmlExportPath = @"C:\temp\Export_XML.xml"; public string OutDefTxt; private ImageList imageList1; private Button bu3Main; DialogResult result; //////////////////////////////////////////////////////////////////////// #region Formular public FrmMain() { InitializeComponent(); } private System.Windows.Forms.ToolStripStatusLabel lblStatus2; private System.Windows.Forms.Button bu1Main; private System.Windows.Forms.Button bu2Main; private System.Windows.Forms.GroupBox gb1Main; private System.Windows.Forms.CheckBox cbGravur; private System.Windows.Forms.CheckBox cbLPlan; private System.Windows.Forms.CheckBox cbEplan; private System.Windows.Forms.GroupBox gb2Main; private System.Windows.Forms.CheckBox cbSch; private System.Windows.Forms.CheckBox cbPneu; private System.Windows.Forms.CheckBox cbHyd; private System.Windows.Forms.CheckBox cbSkl; private CheckBox cbKomp; /// /// Erforderliche Designervariable. /// private System.ComponentModel.IContainer components = null; /// /// Verwendete Ressourcen bereinigen. /// /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Vom Windows Form-Designer generierter Code /// /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain)); this.lblStatus2 = new System.Windows.Forms.ToolStripStatusLabel(); this.bu1Main = new System.Windows.Forms.Button(); this.bu2Main = new System.Windows.Forms.Button(); this.gb1Main = new System.Windows.Forms.GroupBox(); this.cbGravur = new System.Windows.Forms.CheckBox(); this.cbLPlan = new System.Windows.Forms.CheckBox(); this.cbEplan = new System.Windows.Forms.CheckBox(); this.gb2Main = new System.Windows.Forms.GroupBox(); this.cbSch = new System.Windows.Forms.CheckBox(); this.cbPneu = new System.Windows.Forms.CheckBox(); this.cbHyd = new System.Windows.Forms.CheckBox(); this.cbSkl = new System.Windows.Forms.CheckBox(); this.cbKomp = new System.Windows.Forms.CheckBox(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.bu3Main = new System.Windows.Forms.Button(); //this.Icon = new Icon(@"\\SR-FILE03\Daten\EB\ebdata\EPLAN2_2\Scripte\SWZ\Bilder\LOGO.ico"); this.gb1Main.SuspendLayout(); this.gb2Main.SuspendLayout(); this.SuspendLayout(); // // lblStatus2 // this.lblStatus2.Margin = new System.Windows.Forms.Padding(2, 3, 0, 2); this.lblStatus2.Name = "lblStatus2"; this.lblStatus2.Size = new System.Drawing.Size(235, 17); this.lblStatus2.Text = "Letzte Änderung: 2009-10-23 - Johann Weiher"; // // bu1Main // this.bu1Main.Location = new System.Drawing.Point(13, 173); this.bu1Main.Name = "bu1Main"; this.bu1Main.Size = new System.Drawing.Size(75, 23); this.bu1Main.TabIndex = 0; this.bu1Main.Text = "OK"; this.bu1Main.UseVisualStyleBackColor = true; this.bu1Main.Click += new System.EventHandler(this.bu1Main_Click); // // bu2Main // this.bu2Main.Location = new System.Drawing.Point(229, 173); this.bu2Main.Name = "bu2Main"; this.bu2Main.Size = new System.Drawing.Size(75, 23); this.bu2Main.TabIndex = 1; this.bu2Main.Text = "Abbrechen"; this.bu2Main.UseVisualStyleBackColor = true; this.bu2Main.Click += new System.EventHandler(this.bu2Main_Click); // // gb1Main // this.gb1Main.Controls.Add(this.cbGravur); this.gb1Main.Controls.Add(this.cbLPlan); this.gb1Main.Controls.Add(this.cbEplan); this.gb1Main.Location = new System.Drawing.Point(13, 35); this.gb1Main.Name = "gb1Main"; this.gb1Main.Size = new System.Drawing.Size(145, 120); this.gb1Main.TabIndex = 2; this.gb1Main.TabStop = false; this.gb1Main.Text = "Gruppen Auswahl Elektrotechnik"; // // cbGravur // this.cbGravur.AutoSize = true; this.cbGravur.Location = new System.Drawing.Point(6, 88); this.cbGravur.Name = "cbGravur"; this.cbGravur.Size = new System.Drawing.Size(88, 17); this.cbGravur.TabIndex = 2; this.cbGravur.Text = "Gravur-Platte"; this.cbGravur.UseVisualStyleBackColor = true; // // cbLPlan // this.cbLPlan.AutoSize = true; this.cbLPlan.Location = new System.Drawing.Point(6, 65); this.cbLPlan.Name = "cbLPlan"; this.cbLPlan.Size = new System.Drawing.Size(70, 17); this.cbLPlan.TabIndex = 1; this.cbLPlan.Text = "Lageplan"; this.cbLPlan.UseVisualStyleBackColor = true; // // cbEplan // this.cbEplan.AutoSize = true; this.cbEplan.Location = new System.Drawing.Point(6, 42); this.cbEplan.Name = "cbEplan"; this.cbEplan.Size = new System.Drawing.Size(79, 17); this.cbEplan.TabIndex = 0; this.cbEplan.Text = "Elektroplan"; this.cbEplan.UseVisualStyleBackColor = true; // // gb2Main // this.gb2Main.Controls.Add(this.cbSch); this.gb2Main.Controls.Add(this.cbPneu); this.gb2Main.Controls.Add(this.cbHyd); this.gb2Main.Location = new System.Drawing.Point(186, 35); this.gb2Main.Name = "gb2Main"; this.gb2Main.Size = new System.Drawing.Size(118, 120); this.gb2Main.TabIndex = 6; this.gb2Main.TabStop = false; this.gb2Main.Text = "Gruppen Auswahl Fluid"; this.gb2Main.Enter += new System.EventHandler(this.groupBox1_Enter); // // cbSch // this.cbSch.AutoSize = true; this.cbSch.Location = new System.Drawing.Point(11, 88); this.cbSch.Name = "cbSch"; this.cbSch.Size = new System.Drawing.Size(84, 17); this.cbSch.TabIndex = 2; this.cbSch.Text = "Schmierplan"; this.cbSch.UseVisualStyleBackColor = true; // // cbPneu // this.cbPneu.AutoSize = true; this.cbPneu.Location = new System.Drawing.Point(11, 65); this.cbPneu.Name = "cbPneu"; this.cbPneu.Size = new System.Drawing.Size(96, 17); this.cbPneu.TabIndex = 1; this.cbPneu.Text = "Pneumatikplan"; this.cbPneu.UseVisualStyleBackColor = true; // // cbHyd // this.cbHyd.AutoSize = true; this.cbHyd.Location = new System.Drawing.Point(11, 42); this.cbHyd.Name = "cbHyd"; this.cbHyd.Size = new System.Drawing.Size(90, 17); this.cbHyd.TabIndex = 0; this.cbHyd.Text = "Hydraulikplan"; this.cbHyd.UseVisualStyleBackColor = true; // // cbSkl // this.cbSkl.AutoSize = true; this.cbSkl.Checked = true; this.cbSkl.CheckState = System.Windows.Forms.CheckState.Checked; this.cbSkl.Cursor = System.Windows.Forms.Cursors.SizeWE; this.cbSkl.Enabled = false; this.cbSkl.Location = new System.Drawing.Point(127, 12); this.cbSkl.Name = "cbSkl"; this.cbSkl.Size = new System.Drawing.Size(95, 17); this.cbSkl.TabIndex = 7; this.cbSkl.Text = "Mit Stücklisten"; this.cbSkl.UseVisualStyleBackColor = true; // // cbKomp // this.cbKomp.AutoSize = true; this.cbKomp.Location = new System.Drawing.Point(19, 12); this.cbKomp.Name = "cbKomp"; this.cbKomp.Size = new System.Drawing.Size(102, 17); this.cbKomp.TabIndex = 8; this.cbKomp.Text = "Projekt komplett"; this.cbKomp.UseVisualStyleBackColor = true; this.cbKomp.CheckedChanged += new System.EventHandler(this.cbKomp_CheckedChanged); // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1.ImageSize = new System.Drawing.Size(16, 16); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // bu3Main // this.bu3Main.Location = new System.Drawing.Point(105, 173); this.bu3Main.Name = "bu3Main"; this.bu3Main.Size = new System.Drawing.Size(107, 23); this.bu3Main.TabIndex = 9; this.bu3Main.Text = "Mit Ordner öffnen"; this.bu3Main.UseVisualStyleBackColor = true; this.bu3Main.Click += new System.EventHandler(this.bu3Main_Click); // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(318, 213); this.Controls.Add(this.bu3Main); this.Controls.Add(this.cbKomp); this.Controls.Add(this.cbSkl); this.Controls.Add(this.gb2Main); this.Controls.Add(this.gb1Main); this.Controls.Add(this.bu2Main); this.Controls.Add(this.bu1Main); this.ShowIcon = false; //this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "FrmMain"; this.Text = "PDF Drucken"; this.gb1Main.ResumeLayout(false); this.gb1Main.PerformLayout(); this.gb2Main.ResumeLayout(false); this.gb2Main.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion #endregion // Code für das Formular //////////////////////////////////////////////////////////////////////// // Action //////////////////////////////////////////////////////////////////////// [Start] [DeclareAction("FORM_TEMPLATE")] public void FrmTemplateVoid() { // Form aufrufen FrmMain Frm1 = new FrmMain(); Frm1.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; Frm1.ShowDialog(); return; } private void groupBox1_Enter(object sender, System.EventArgs e) { } private void bu1Main_Click(object sender, System.EventArgs e) // Drucken { //////////////////////////////////////////////////////////////////////// // 0 = Stromlaufplan // 1 = Lageplan // 2 = Gravur // 3 = Hydraulik // 4 = Pneumatik // 5 = Schmierung // 6 = Komplett // 7= Stückliste //////////////////////////////////////////////////////////////////////// iType = DefType(); // Was soll alle gedruckt werden if (iType[6] == 1) { Choice_complete(); if (result == DialogResult.Yes) { this.Close(); } } if (iType[0] == 1 || iType[1] == 1 || iType[2] == 1 || iType[3] == 1 || iType[4] == 1 || iType[5] == 1 && iType[6] == 0) { Choice_single(); if (result == DialogResult.Yes) { this.Close(); } } if (iType[0] == 0 && iType[1] == 0 && iType[2] == 0 && iType[3] == 0 && iType[4] == 0 && iType[5] == 0 && iType[6] == 0) { MessageBox.Show("Es wurde keine Auswahl getroffen", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void bu2Main_Click(object sender, System.EventArgs e) { this.Close(); } private void bu3Main_Click(object sender, EventArgs e) //Drucken mit Ordner öffnen { //////////////////////////////////////////////////////////////////////// // 0 = Stromlaufplan // 1 = Lageplan // 2 = Gravur // 3 = Hydraulik // 4 = Pneumatik // 5 = Schmierung // 6 = Komplett // 7= Stückliste //////////////////////////////////////////////////////////////////////// iType = DefType(); // Was soll alle gedruckt werden if (iType[6] == 1) { Choice_complete(); if (result == DialogResult.Yes) { this.Close(); OpenExplorer(PDFExportPath1 + FindLink("10009", "\\", ".")); } } if (iType[0] == 1 || iType[1] == 1 || iType[2] == 1 || iType[3] == 1 || iType[4] == 1 || iType[5] == 1 && iType[6] == 0) { Choice_single(); if (result == DialogResult.Yes) { this.Close(); OpenExplorer(PDFExportPath1 + FindLink("10009", "\\", ".")); } } if (iType[0] == 0 && iType[1] == 0 && iType[2] == 0 && iType[3] == 0 && iType[4] == 0 && iType[5] == 0 && iType[6] == 0) { MessageBox.Show("Es wurde keine Auswahl getroffen", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void IndexOf(string v1, int v2) { throw new NotImplementedException(); } private void cbKomp_CheckedChanged(object sender, System.EventArgs e) { if (cbKomp.Checked) { gb1Main.Enabled = false; gb2Main.Enabled = false; cbEplan.Checked = false; cbLPlan.Checked = false; cbGravur.Checked = false; cbHyd.Checked = false; cbPneu.Checked = false; cbSch.Checked = false; } else if (! cbKomp.Checked) { gb1Main.Enabled = true; gb2Main.Enabled = true; } } public void Choice_complete() // PDF Druck komplett { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("ScriptFile", @"F:\EB\ebdata\EPLAN2_2\Scripte\SWZ\MTK_pdf_complete.cs"); oCLI.Execute("ExecuteScript", acc); } public void Choice_single() //PDF Druck seperat { XmlExport(FullProjectPath(), XmlExportPath); strLanguage = GetProjectSettings(XmlExportPath, "/Settings/CAT/MOD/Setting[@name='DISPLAYED_LANGUAGES']/Val").Replace(";", ""); // Sprache ermitteln if (strLanguage.Equals("de_DE")) { //Function_Export_DE_Complete(); indexLang = "DE"; } else if (strLanguage.Equals("en_US")) { //Function_Export_EN_Complete(); indexLang = "EN"; } //MessageBox.Show(strLanguage); Function_Export_Single(iType); } // PDF Export mit Sprachen-Kürzel separiert nach Gewerken public void Function_Export_Single(int[] arrTypeOut) { string strFullProjectname = PathMap.SubstitutePath("$(P)"); //string strProjectpath = // PathMap.SubstitutePath("$(PROJECTPATH)" + @"\"); //string strProjectname = // PathMap.SubstitutePath("$(PROJECTNAME)"); //Read Info from XML string CommShort = GetProjectProperty("10014", "0"); //MessageBox.Show("Kompletter Projekt Pfad:\n " + strFullProjectname + "\n\n" + "Seriennummer:\n" + CommShort,"Pfad Kontrolle"); CommShort = CommShort.Replace("-", ""); DialogResult Result = MessageBox.Show( "Sollen einzelne PDF's für das Projekt\n'" + CommShort + "' \nund der Sprache '" + strLanguage + "'\nerzeugt werden?", "PDF-Export", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if (Result == DialogResult.Yes) { Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(true); oProgress.SetAskOnCancel(true); oProgress.BeginPart(100, ""); oProgress.ShowImmediately(); CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc_e = new ActionCallingContext(); //Elektro ActionCallingContext acc_h = new ActionCallingContext(); //Hydraulik ActionCallingContext acc_p = new ActionCallingContext(); //Pneumatik ActionCallingContext acc_s = new ActionCallingContext(); //Schmierung ActionCallingContext acc_m = new ActionCallingContext(); //Magazin ActionCallingContext acc_r = new ActionCallingContext(); //Roboter ActionCallingContext acc_g = new ActionCallingContext(); //Gravur ActionCallingContext acc_l = new ActionCallingContext(); //Endschalter Lageplan //Elektro if (arrTypeOut[0] == 1) { acc_e.AddParameter("TYPE", "PDFPROJECTSCHEME"); acc_e.AddParameter("PROJECTNAME", strFullProjectname); acc_e.AddParameter("EXPORTFILE", PDFExportPath + "E" + CommShort + indexLang + "000.PDF"); acc_e.AddParameter("EXPORTSCHEME", "SWZ Elektrotechnik"); oCLI.Execute("export", acc_e); } //Endschalter Lageplan if (arrTypeOut[1] == 1) { acc_l.AddParameter("TYPE", "PDFPROJECTSCHEME"); acc_l.AddParameter("PROJECTNAME", strFullProjectname); acc_l.AddParameter("EXPORTFILE", PDFExportPath + "L" + CommShort + indexLang + "000.PDF"); acc_l.AddParameter("EXPORTSCHEME", "SWZ Endschalter Lageplan"); oCLI.Execute("export", acc_l); } //Gravurplatte if (arrTypeOut[2] == 1) { acc_g.AddParameter("TYPE", "PDFPROJECTSCHEME"); acc_g.AddParameter("PROJECTNAME", strFullProjectname); acc_g.AddParameter("EXPORTFILE", PDFExportPath + CommShort + indexLang + "_Gravur.PDF"); acc_g.AddParameter("EXPORTSCHEME", "SWZ Gravurplatte"); oCLI.Execute("export", acc_g); } //Hydraulik if (arrTypeOut[3] == 1) { acc_h.AddParameter("TYPE", "PDFPROJECTSCHEME"); acc_h.AddParameter("PROJECTNAME", strFullProjectname); acc_h.AddParameter("EXPORTFILE", PDFExportPath + "H" + CommShort + indexLang + "000.PDF"); acc_h.AddParameter("EXPORTSCHEME", "SWZ Hydraulik"); oCLI.Execute("export", acc_h); } //Pneumatik if (arrTypeOut[4] == 1) { acc_p.AddParameter("TYPE", "PDFPROJECTSCHEME"); acc_p.AddParameter("PROJECTNAME", strFullProjectname); acc_p.AddParameter("EXPORTFILE", PDFExportPath + "P" + CommShort + indexLang + "000.PDF"); acc_p.AddParameter("EXPORTSCHEME", "SWZ Pneumatik"); oCLI.Execute("export", acc_p); } //Schmierung if (arrTypeOut[5] == 1) { acc_s.AddParameter("TYPE", "PDFPROJECTSCHEME"); acc_s.AddParameter("PROJECTNAME", strFullProjectname); acc_s.AddParameter("EXPORTFILE", PDFExportPath + "S" + CommShort + indexLang + "000.PDF"); acc_s.AddParameter("EXPORTSCHEME", "SWZ Schmierung"); oCLI.Execute("export", acc_s); } MessageBox.Show(" :-) Export Abgeschlossen (-: "); oProgress.EndPart(true); } return; } // definiere die Auswahl public int[] DefType() { int[] OutDefType = new int[8]; if (cbEplan.Checked) { OutDefType[0] = 1; } //Stromlaufplan if (cbLPlan.Checked) { OutDefType[1] = 1; } //Gravurplatte if (cbGravur.Checked) { OutDefType[2] = 1; } //Lageplan if (cbHyd.Checked) { OutDefType[3] = 1; } //Hydraulik if (cbPneu.Checked) { OutDefType[4] = 1; } //Pneumatik if (cbSch.Checked) { OutDefType[5] = 1; } //Schmierung if (cbKomp.Checked) { OutDefType[6] = 1; } //Kompletten Plan if (cbSkl.Checked) { OutDefType[7] = 1; } //Stückliste return OutDefType; } // Returns the EPLAN Project Path private static string FullProjectPath() { ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("TYPE", "PROJECT"); string projectPath = string.Empty; new CommandLineInterpreter().Execute("selectionset", acc); acc.GetParameter("PROJECT", ref projectPath); return projectPath; } // Read EPLAN XML-ProjectInfo and returns the value private static string GetValueSettingsXml(string filename, string url) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(filename); XmlNodeList rankListSchemaName = xmlDocument.SelectNodes(url); if (rankListSchemaName != null && rankListSchemaName.Count > 0) { // Get Text from MultiLanguage or not :) string value = rankListSchemaName[0].InnerText; return value; } else { return null; } } // Get value from XML private string GetProjectSettings(string strProjcetXml, string strURL) { XmlDocument doc = new XmlDocument(); doc.Load(strProjcetXml); XmlNode node = doc.SelectSingleNode(strURL); string strSetting = node.InnerText; return strSetting; } // Trim 5 top most right character from string private string TrimString(string strToTrim, string ch1, string ch2, string ch3, string ch4, string ch5) { strToTrim = strToTrim.Replace(ch1, "").Replace(ch2, "").Replace(ch3, "").Replace(ch4, "").Replace(ch5, ""); strToTrim = strToTrim.Remove(strToTrim.Length - 8); return strToTrim; } //Export XML File private void XmlExport(string FullProjectPath, string TempPath) { ActionCallingContext actionCallingContext = new ActionCallingContext(); actionCallingContext.AddParameter("prj", FullProjectPath); //actionCallingContext.AddParameter("node", ""); actionCallingContext.AddParameter("XMLFile", TempPath); new CommandLineInterpreter().Execute("XSettingsExport", actionCallingContext); } //Read Eplan XML and get the Node Info private static string GetProjectProperty(string id, string index) { string value = null; ActionCallingContext actionCallingContext = new ActionCallingContext(); actionCallingContext.AddParameter("id", id); actionCallingContext.AddParameter("index", index); new CommandLineInterpreter().Execute("GetProjectProperty", actionCallingContext); actionCallingContext.GetParameter("value", ref value); return value; } private void pictureBox1_Click(object sender, EventArgs e) { } private static void OpenExplorer(string path) { if (Directory.Exists(path)) Process.Start("explorer.exe", path); } private string FindLink(string ID,string sStart, string sEnd) // Finde in XML ID, in String eine Zeichenkette von... bis { int iStart; int iEnd; iStart = GetProjectProperty(ID, "0").LastIndexOf(sStart); iEnd = GetProjectProperty(ID, "0").LastIndexOf(sEnd); return GetProjectProperty(ID, "0").Substring(iStart, iEnd - iStart).Replace(@"\", ""); } }