//******************************************************************** //Projekt: ExportProjektAsPDF //Erstellt von: Eugen S. //Esretllt am: 19.03.2010 //Letzte Änderung: 21.04.2010 //Version: 2.0 //******************************************************************** using System.Diagnostics; using System.IO; public class ExportProjectAsPDF : System.Windows.Forms.Form { public string ProjectData = string.Empty; //Globale Variablen für absoluten Pfad public string ProjectPath = string.Empty; //Globale Variablen für Projektpfad public string ProjectName = string.Empty; //Globale Variablen für Projektname #region WindowsForm public ExportProjectAsPDF() { InitializeComponent(); } private System.Windows.Forms.Label lblPfad; private System.Windows.Forms.TextBox txtPfad; private System.Windows.Forms.Button btnPfad; private System.Windows.Forms.Button btnOK; private System.Windows.Forms.Button btnAbrrechen; // 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.lblPfad = new System.Windows.Forms.Label(); this.txtPfad = new System.Windows.Forms.TextBox(); this.btnPfad = new System.Windows.Forms.Button(); this.btnOK = new System.Windows.Forms.Button(); this.btnAbrrechen = new System.Windows.Forms.Button(); this.SuspendLayout(); // // lblPfad // this.lblPfad.AutoSize = true; this.lblPfad.Location = new System.Drawing.Point(13, 13); this.lblPfad.Name = "lblPfad"; this.lblPfad.Size = new System.Drawing.Size(59, 13); this.lblPfad.TabIndex = 0; this.lblPfad.Text = "PDF-Pfad:"; // // txtPfad // this.txtPfad.Location = new System.Drawing.Point(12, 29); this.txtPfad.Name = "txtPfad"; this.txtPfad.ReadOnly = true; this.txtPfad.Size = new System.Drawing.Size(307, 20); this.txtPfad.TabIndex = 1; // // btnPfad // this.btnPfad.Location = new System.Drawing.Point(325, 29); this.btnPfad.Name = "btnPfad"; this.btnPfad.Size = new System.Drawing.Size(30, 21); this.btnPfad.TabIndex = 2; this.btnPfad.Text = "..."; this.btnPfad.UseVisualStyleBackColor = true; this.btnPfad.Click += new System.EventHandler(this.btnPfad_Click); // // btnOK // this.btnOK.Location = new System.Drawing.Point(108, 75); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(75, 23); this.btnOK.TabIndex = 3; this.btnOK.Text = "OK"; this.btnOK.UseVisualStyleBackColor = true; this.btnOK.Click += new System.EventHandler(this.btnOK_Click); // // btnAbrrechen // this.btnAbrrechen.Location = new System.Drawing.Point(190, 74); this.btnAbrrechen.Name = "btnAbrrechen"; this.btnAbrrechen.Size = new System.Drawing.Size(75, 23); this.btnAbrrechen.TabIndex = 4; this.btnAbrrechen.Text = "Abbrechen"; this.btnAbrrechen.UseVisualStyleBackColor = true; this.btnAbrrechen.Click += new System.EventHandler(this.btnAbrrechen_Click); // // FormPDFexport // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(372, 116); this.Controls.Add(this.btnAbrrechen); this.Controls.Add(this.btnOK); this.Controls.Add(this.btnPfad); this.Controls.Add(this.txtPfad); this.Controls.Add(this.lblPfad); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(380, 150); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(380, 150); this.Name = "FormPDFexport"; this.ShowIcon = false; this.ShowInTaskbar = false; this.Text = "Gesamtes Projekt als PDF exportieren"; this.ResumeLayout(false); this.PerformLayout(); } #endregion #endregion #region Actions // Action ProjectExportAsPDF initialisieren [DeclareAction("ExportProjectAsPDF")] public void ExportProjectAsPDFVoid() { GetProjectData(); // PDF: Prüfung, ob die Datei schon vorhanden ist. if (File.Exists(ProjectPath + ProjectName + ".pdf")) { DialogResult oDialogResult = MessageBox.Show("Die PDF-Datei existiert bereits. Soll diese Datei überschrieben werden?", "Gesamtes Projekt als PDF exportieren", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (oDialogResult == DialogResult.Yes) { PDFexportFunction(ProjectPath, ProjectName); } return; } else { PDFexportFunction(ProjectPath, ProjectName); } } // Action ProjectExportAsPDFwithPath initialisieren [DeclareAction("ProjectExportAsPDFwithPath")] public void FormAufruf() { GetProjectData(); // Form aufrufen this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.txtPfad.Text = ProjectPath + ProjectName + ".pdf"; this.ShowDialog(); return; } //Button für die Pfadauswahl. private void btnPfad_Click(object sender, EventArgs e) { string SaveData = string.Empty; System.Windows.Forms.SaveFileDialog objSave = new SaveFileDialog(); objSave.Title = "Speichern unter"; objSave.Filter = "Adobe PDF-Datei (*.pdf)|*.pdf"; objSave.OverwritePrompt = false; objSave.InitialDirectory = ProjectPath; objSave.FileName = ProjectName; if (objSave.ShowDialog() == DialogResult.OK) { SaveData = objSave.FileName; txtPfad.Text = SaveData; ProjectName = System.IO.Path.GetFileNameWithoutExtension(SaveData); ProjectPath = System.IO.Path.GetDirectoryName(SaveData) + @"\"; } } //Button für den PDF Export. private void btnOK_Click(object sender, EventArgs e) { new CommandLineInterpreter().Execute("EsGenerateConnections"); // PDF: Prüfung, ob die Datei schon vorhanden ist. if (File.Exists(ProjectPath + ProjectName + ".pdf")) { DialogResult oDialogResult = MessageBox.Show("Die PDF-Datei existiert bereits. Soll diese Datei überschrieben werden?", "Gesamtes Projekt als PDF exportieren", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (oDialogResult == DialogResult.Yes) { //Form ausblenden this.Hide(); PDFexportFunction(ProjectPath, ProjectName); } } else { //Form ausblenden this.Hide(); PDFexportFunction(ProjectPath, ProjectName); } Close(); } //Button zum Schließen des Dialogs. private void btnAbrrechen_Click(object sender, EventArgs e) { Close(); } #endregion // Funktion für den PDF-Export private void PDFexportFunction(string sProjectPath, string sProjectName) { // PDF: Datei prüfen if (File.Exists(sProjectPath + sProjectName + ".pdf")) { try { File.Delete(sProjectPath + sProjectName + ".pdf"); } catch (IOException) { MessageBox.Show("Die Ausgabedatei\n" + sProjectPath + sProjectName + ".pdf" + "\nwird verwendet." + Environment.NewLine + "Schließen Sie die Datei und versuchen Sie es erneut.", "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } // PDF: Exportieren Progress progress = new Progress("SimpleProgress"); progress.BeginPart(100,""); progress.SetAllowCancel(true); if (!progress.Canceled()) { //PDF Parameter ActionCallingContext exportContext = new ActionCallingContext(); exportContext.AddParameter("TYPE", "PDFPROJECT"); exportContext.AddParameter("EXPORTFILE", sProjectPath + sProjectName); exportContext.AddParameter("USESIMPLELINK", "1"); //1 = einfache Sprungfunktion exportContext.AddParameter("FASTWEBVIEW", "1"); //1 = schnelle Web-Anzeige exportContext.AddParameter("READONLYEXPORT", "1"); //1 = PDF wird schreibgeschützt exportContext.AddParameter("BLACKWHITE", "0"); //0 = PDF wird farbig new CommandLineInterpreter().Execute("export", exportContext); progress.EndPart(); } progress.EndPart(true); // PDF: Öffnen Process pPDF = new Process(); System.Diagnostics.Process.Start(sProjectPath + sProjectName + ".pdf"); } // Funktion für Ermittlung der Projektdaten public void GetProjectData() { // Projektname und -pfad ermitteln string sSelectedProjectData = string.Empty; Eplan.EplApi.ApplicationFramework.ActionCallingContext ctx = new Eplan.EplApi.ApplicationFramework.ActionCallingContext(); ctx.AddParameter("TYPE", "PROJECT"); CommandLineInterpreter oCLI = new CommandLineInterpreter(); bool bRet = oCLI.Execute("selectionset", ctx); if (bRet == true) { ctx.GetParameter("PROJECT", ref sSelectedProjectData); } ProjectData = System.IO.Path.GetFullPath(sSelectedProjectData); ProjectName = System.IO.Path.GetFileNameWithoutExtension(sSelectedProjectData); ProjectPath = System.IO.Path.GetDirectoryName(sSelectedProjectData) + @"\"; } }