//Betron Control Systems GmbH / Großer Teil 8 / 32130 Enger / www.betron.de // //Autor: Andrej Robert (Entwicklung & Konstruktion) // //Programm: LogBuch / Protokoll zum Projekt führen //################################################################################################################################# //Version 0.1.0 29.08.2018 //Prüfung & Erstellung einer txt-Datei im DOC Ordner //Eingabe und Kommentar Tab-getrennt //Bestehendes Menü erweitert: STRG + L //################################################################################################################################# //Version 0.1.1 14.03.2019 // CheckBox für Seite protokollieren und Uhrzeit protokollieren // auslesen der Seite bzw Markierung im Seitennavi => Einbindung vom Script https://suplanus.de/selectionset-pages/ (Johann Weiher) //################################################################################################################################# //Version 0.1.2 27.03.2020, Frank Schöneck // DOC Ordner wird korrekt angelegt wenn er noch nicht existiert. //################################################################################################################################# //Version 0.1.3 07.03.2021, Alessandro Alfano // Tradotto in italiano // Inserito casella per selezionare se un documento è stato gia stampato // Inserito Tasto pdf per la stama delle pagine modificate // Inserito Tasto STAMPARE per la stampare //################################################################################################################################# using System; using System.Diagnostics; using System.IO; public class PagePdf { [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.ContextMenu oMenu = new Eplan.EplApi.Gui.ContextMenu(); Eplan.EplApi.Gui.ContextMenuLocation oLocation = new Eplan.EplApi.Gui.ContextMenuLocation( "PmPageObjectTreeDialog", "1007" ); oMenu.AddMenuItem( oLocation, "Crea PDF V4", "PagePdf V4", true, false ); } [DeclareAction("PagePdf")] public void PagePdfVoid() { FolderBrowserDialog fbd = new FolderBrowserDialog(); CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); if (fbd.ShowDialog() != DialogResult.OK) { return; } Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(true); oProgress.SetAskOnCancel(true); oProgress.BeginPart(100, ""); oProgress.ShowImmediately(); try { string strPages = string.Empty; acc.AddParameter("TYPE", "PAGES"); oCLI.Execute("selectionset", acc); acc.GetParameter("PAGES", ref strPages); foreach (string CurrentPage in strPages.Split(';')) { if (!oProgress.Canceled()) { acc.AddParameter("TYPE", "PDFPAGESSCHEME"); acc.AddParameter("PAGENAME", CurrentPage); acc.AddParameter("EXPORTFILE", fbd.SelectedPath + @"\" + CurrentPage); acc.AddParameter("EXPORTSCHEME", "EPLAN_default_value"); oCLI.Execute("export", acc); } else { oProgress.EndPart(true); return; } } Process.Start(fbd.SelectedPath); oProgress.EndPart(true); } catch (System.Exception ex) { oProgress.EndPart(true); MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } public partial class EPlanP8LogBuch : System.Windows.Forms.Form { private TextBox LogBookText; private Label ProjectName; private Button LeaveMaskButton; private Button LOGBOOKWRITE; private Button LOGSTAMPANTE; ///SCRIPT STAMPARE INIZIO private Button LOGPDF; private Button EXPORTPDF; private TextBox LogBookCommentText; public string sProjectpathLogBook; public String tempfile; private CheckBox checkPage; private CheckBox checkTime; private CheckBox checkStampa; #region Vom Windows Form-Designer generierter Code /// /// 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); } /// /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor /// geändert werden. /// private void InitializeComponent() { this.LogBookText = new System.Windows.Forms.TextBox(); this.ProjectName = new System.Windows.Forms.Label(); this.LeaveMaskButton = new System.Windows.Forms.Button(); this.LOGBOOKWRITE = new System.Windows.Forms.Button(); this.LOGSTAMPANTE = new System.Windows.Forms.Button(); this.LOGPDF = new System.Windows.Forms.Button(); this.EXPORTPDF = new System.Windows.Forms.Button(); this.LogBookCommentText = new System.Windows.Forms.TextBox(); this.checkPage = new System.Windows.Forms.CheckBox(); this.checkTime = new System.Windows.Forms.CheckBox(); this.checkStampa = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // LogBookText // this.LogBookText.Location = new System.Drawing.Point(12, 41);// posizione grafica cella inserimento prima riga x,y this.LogBookText.Name = "LogBookText"; this.LogBookText.Size = new System.Drawing.Size(651, 20);// larghezza grafica cella inserimento prima riga x,y this.LogBookText.TabIndex = 1; this.LogBookText.Text = "Motivo della modifica:"; this.LogBookText.Click += new System.EventHandler(this.LogBookText_Click); // Ho messo i due slash per non far eliminare la scritta // // ProjectName // this.ProjectName.AutoSize = true; this.ProjectName.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.ProjectName.ForeColor = System.Drawing.Color.Black; this.ProjectName.Location = new System.Drawing.Point(12, 9); this.ProjectName.Name = "ProjectName"; this.ProjectName.Size = new System.Drawing.Size(127, 22); this.ProjectName.TabIndex = 7; this.ProjectName.Text = "Projektname"; // // LeaveMaskButton // this.LeaveMaskButton.Location = new System.Drawing.Point(549, 107); this.LeaveMaskButton.Name = "LeaveMaskButton"; this.LeaveMaskButton.Size = new System.Drawing.Size(114, 41); this.LeaveMaskButton.TabIndex = 6; this.LeaveMaskButton.Text = "Annulla"; this.LeaveMaskButton.UseVisualStyleBackColor = true; this.LeaveMaskButton.Click += new System.EventHandler(this.LeaveMaskButton_Click); // // LOGBOOKWRITE // this.LOGBOOKWRITE.ForeColor = System.Drawing.SystemColors.ControlText; this.LOGBOOKWRITE.Location = new System.Drawing.Point(431, 107); this.LOGBOOKWRITE.Name = "LOGBOOKWRITE"; this.LOGBOOKWRITE.Size = new System.Drawing.Size(112, 41); this.LOGBOOKWRITE.TabIndex = 5; this.LOGBOOKWRITE.Tag = ""; this.LOGBOOKWRITE.Text = "Salva"; this.LOGBOOKWRITE.UseVisualStyleBackColor = true; this.LOGBOOKWRITE.Click += new System.EventHandler(this.LOGBOOKWRITE_Click); // // LOGSTAMPANTE // this.LOGSTAMPANTE.ForeColor = System.Drawing.SystemColors.ControlText; ///SCRIPT STAMPARE INIZIO this.LOGSTAMPANTE.Location = new System.Drawing.Point(549, 150); this.LOGSTAMPANTE.Name = "STAMPA"; this.LOGSTAMPANTE.Size = new System.Drawing.Size(112, 41); this.LOGSTAMPANTE.TabIndex = 5; this.LOGSTAMPANTE.Tag = ""; this.LOGSTAMPANTE.Text = "STAMPARE"; this.LOGSTAMPANTE.UseVisualStyleBackColor = true; this.LOGSTAMPANTE.Click += new System.EventHandler(this.LOGSTAMPANTE_Click);///SCRIPT STAMPARE FINE // // LOGPDF // this.LOGPDF.ForeColor = System.Drawing.SystemColors.ControlText; this.LOGPDF.Location = new System.Drawing.Point(325, 107); this.LOGPDF.Name = "LOGPDF"; this.LOGPDF.Size = new System.Drawing.Size(100, 44); this.LOGPDF.TabIndex = 5; this.LOGPDF.Tag = ""; this.LOGPDF.Text = "CARTELLE E PAGINE SINGOLE PDF"; this.LOGPDF.UseVisualStyleBackColor = true; this.LOGPDF.Click += new System.EventHandler(this.LOGPDF_Click); // // EXPORTPDF // this.EXPORTPDF.ForeColor = System.Drawing.SystemColors.ControlText; this.EXPORTPDF.Location = new System.Drawing.Point(325, 150); this.EXPORTPDF.Name = "EXPORTPDF"; this.EXPORTPDF.Size = new System.Drawing.Size(100, 41); this.EXPORTPDF.TabIndex = 5; this.EXPORTPDF.Tag = ""; this.EXPORTPDF.Text = "ESPORTA IN PDF"; this.EXPORTPDF.UseVisualStyleBackColor = true; this.EXPORTPDF.Click += new System.EventHandler(this.EXPORTPDF_Click); // // LogBookCommentText // this.LogBookCommentText.Location = new System.Drawing.Point(12, 81); this.LogBookCommentText.Name = "LogBookCommentText"; this.LogBookCommentText.Size = new System.Drawing.Size(651, 20); this.LogBookCommentText.TabIndex = 2; this.LogBookCommentText.Text = "Cosa è cambiato?"; this.LogBookCommentText.Click += new System.EventHandler(this.LogBookCommentText_Click); // // checkPage // this.checkPage.Location = new System.Drawing.Point(12, 120); this.checkPage.Name = "checkPage"; this.checkPage.Size = new System.Drawing.Size(76, 17); this.checkPage.TabIndex = 3; this.checkPage.Text = "Pagine"; this.checkPage.UseVisualStyleBackColor = true; // // checkTime // this.checkTime.Location = new System.Drawing.Point(94, 120); this.checkTime.Name = "checkTime"; this.checkTime.Size = new System.Drawing.Size(89, 17); this.checkTime.TabIndex = 4; this.checkTime.Text = "Log orario"; this.checkTime.UseVisualStyleBackColor = true; // // checkStampa // this.checkStampa.Location = new System.Drawing.Point(190, 120); this.checkStampa.Name = "checkStampa"; this.checkStampa.Size = new System.Drawing.Size(90, 17); this.checkStampa.TabIndex = 5; this.checkStampa.Text = "Da Stampare"; this.checkStampa.UseVisualStyleBackColor = true; // // EPlanP8LogBuch // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);// larghezza grafica della finesta x,y this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.AutoValidate = System.Windows.Forms.AutoValidate.Disable; this.BackColor = System.Drawing.SystemColors.ActiveCaption; this.ClientSize = new System.Drawing.Size(677, 195); this.Controls.Add(this.checkTime); this.Controls.Add(this.checkPage); this.Controls.Add(this.checkStampa); this.Controls.Add(this.LogBookCommentText); this.Controls.Add(this.LOGBOOKWRITE); this.Controls.Add(this.LOGSTAMPANTE); ///SCRIPT STAMPARE this.Controls.Add(this.LOGPDF); this.Controls.Add(this.EXPORTPDF); this.Controls.Add(this.LeaveMaskButton); this.Controls.Add(this.ProjectName); this.Controls.Add(this.LogBookText); this.Name = "EPlanP8LogBuch"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Salva le modifiche"; this.Load += new System.EventHandler(this.EPlanP8LogBuch_Load); this.ResumeLayout(false); this.PerformLayout(); } public EPlanP8LogBuch() { InitializeComponent(); } #endregion #region Function Start der Anwendung bestimmen [DeclareAction("WriteLogBook")] //[DeclareEventHandler("Name_Action")] [Start] public void Function() { EPlanP8LogBuch frm = new EPlanP8LogBuch(); frm.ShowDialog(); return; } [DeclareMenu] public void MenuFunction() { Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu(); oMenu.AddMenuItem( "Registo delle Modifiche V4", // Name: Elemento del menu "WriteLogBook", // Name: Action "LogBuch-Eintrag schreiben", // Statustext 35381, // ID menu: Inserisci / Macro finestra ... 1, // 1 = dopo la voce di menu, 0 = prima della voce di menu false, // Mostra il separatore davanti ad esso false // Mostra separatore dietro ); return; } #endregion #region Eingabemaske EPlanP8LogBuch / Form private void EPlanP8LogBuch_Load(object sender, EventArgs e) { //Controlla se esiste già un file di registro sProjectpathLogBook = PathMap.SubstitutePath("$(DOC)" + @"\Log_delle_Modifiche.txt"); if (!File.Exists(sProjectpathLogBook)) { DialogResult Result = MessageBox.Show("Il file di registro per questo progetto non esiste!\nCrearlo?", "Informazioni", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (Result == DialogResult.No) { this.Close(); } else { Directory.CreateDirectory(PathMap.SubstitutePath("$(DOC)")); File.Create(sProjectpathLogBook).Close(); } } //Anzeigen des Projektes in der Form string strProjectName = PathMap.SubstitutePath("$(PROJECTNAME)"); this.ProjectName.Text = "Modifiche per: " + strProjectName; } #endregion #region Abbruch - Maske schließen private void LeaveMaskButton_Click(object sender, EventArgs e) { this.Close(); } #endregion #region Eintrag in die .txt schreiben private void LOGBOOKWRITE_Click(object sender, EventArgs e) { if (LogBookText.Text == "Motivo della modifica") { DialogResult Result = MessageBox.Show("Inserire Motivo!", "Informazione", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { if (LogBookCommentText.Text == "Riga di commento") { LogBookCommentText.Text = ""; } string user = Environment.UserName; //using (StreamWriter w = File.AppendText(sProjectpathLogBook)) { Log(LogBookText.Text, LogBookCommentText.Text, user); } using (StreamReader r = File.OpenText(sProjectpathLogBook)) { DumpLog(r); } this.Close(); } } public void Log(string logMessage, string logComment, string loguser) { tempfile = Path.GetTempFileName(); using (TextWriter w = new StreamWriter(tempfile)) using (StreamReader reader = new StreamReader(sProjectpathLogBook)) { w.Write("\r\n\n***** Ultima Modifica : "); if (checkTime.Checked) { w.WriteLine("{0} {1} \tModificato da: {2} *****", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString(), loguser); } else { w.WriteLine("{0} \tModificato da: {1} *****", DateTime.Now.ToLongDateString(), loguser); } w.WriteLine("\n"); if (checkStampa.Checked) { w.WriteLine("\t *****DA STAMPARE***** ", loguser); } else { w.WriteLine("\t *****GIA' STAMPATO***** ", loguser); } w.WriteLine("\n"); w.WriteLine("Motivo della Modifica : {0}", logMessage); w.WriteLine("Commento : {0}", logComment); if (checkPage.Checked) { var pages = GetPages(); try { foreach (var page in pages) { ActionCallingContext actionCallingContext = new ActionCallingContext(); actionCallingContext.AddParameter("PAGENAME", page); w.WriteLine(" ° Pagina: {0}", page); } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } w.WriteLine("\n"); w.WriteLine("******************************************************************************************"); while (!reader.EndOfStream) w.WriteLine(reader.ReadLine()); } File.Copy(tempfile, sProjectpathLogBook, true); } public static void DumpLog(StreamReader r) { string line; while ((line = r.ReadLine()) != null) { Console.WriteLine(line); } } #endregion #region GetPages private static string[] GetPages() { ActionCallingContext actionCallingContext = new ActionCallingContext(); string pagesString = string.Empty; actionCallingContext.AddParameter("TYPE", "PAGES"); new CommandLineInterpreter().Execute("selectionset", actionCallingContext); actionCallingContext.GetParameter("PAGES", ref pagesString); string[] pages = pagesString.Split(';'); return pages; } #endregion #region TextBox-Felder markieren private void LogBookText_Click(object sender, EventArgs e) { if (LogBookText.Text == "Titolo") { LogBookText.SelectAll(); } } private void LogBookCommentText_Click(object sender, EventArgs e) { if (LogBookCommentText.Text == "Kommentarzeile") { LogBookCommentText.SelectAll(); } } //[DeclareAction("PagePdf")] private void LOGPDF_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); if (fbd.ShowDialog() != DialogResult.OK) { return; } Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(true); oProgress.SetAskOnCancel(true); oProgress.BeginPart(100, ""); oProgress.ShowImmediately(); try { string strPages = string.Empty; acc.AddParameter("TYPE", "PAGES"); oCLI.Execute("selectionset", acc); acc.GetParameter("PAGES", ref strPages); foreach (string CurrentPage in strPages.Split(';')) { if (!oProgress.Canceled()) { acc.AddParameter("TYPE", "PDFPAGESSCHEME"); acc.AddParameter("PAGENAME", CurrentPage); acc.AddParameter("EXPORTFILE", fbd.SelectedPath + @"\" + CurrentPage); acc.AddParameter("EXPORTSCHEME", "EPLAN_default_value"); oCLI.Execute("export", acc); } else { oProgress.EndPart(true); return; } } Process.Start(fbd.SelectedPath); oProgress.EndPart(true); } catch (System.Exception ex) { oProgress.EndPart(true); MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } } /////////////////////////////////////////////////////////SCRIPT STAMPARE INIZIO private void LOGSTAMPANTE_Click(object sender, EventArgs e) { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); string strPages = string.Empty; acc.AddParameter("TYPE", "PAGES"); oCLI.Execute("selectionset", acc); acc.GetParameter("PAGES", ref strPages); Progress oProgress = new Progress("SimpleProgress"); oProgress.SetAllowCancel(true); oProgress.SetAskOnCancel(true); oProgress.SetNeededSteps(3); oProgress.SetTitle("Drucken"); oProgress.ShowImmediately(); foreach (string Page in strPages.Split(';')) { if (!oProgress.Canceled()) { acc.AddParameter("PAGENAME", Page); oCLI.Execute("print", acc); } else { break; } } oProgress.EndPart(true); return; } public string GetProject() { string strProject = ""; ActionCallingContext ProjectContext = new ActionCallingContext(); ProjectContext.AddParameter("TYPE", "PROJECT"); new CommandLineInterpreter().Execute("selectionset", ProjectContext); ProjectContext.GetParameter("PROJECT", ref strProject); return strProject; } private void EXPORTPDF_Click(object sender, EventArgs e) { string[] projectPage; string projectPages; string project; projectPage = GetPages(); project = GetProject(); MessageBox.Show(project); FolderBrowserDialog fbd = new FolderBrowserDialog(); CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); try { ActionCallingContext PDFExportContext = new ActionCallingContext(); PDFExportContext.AddParameter("TYPE", "PDFPAGESSCHEME"); PDFExportContext.AddParameter("PROJECTNAME", project); for (int i = 1; i <= projectPage.Length; i++) { PDFExportContext.AddParameter("PAGENAME" + i.ToString(), projectPage[i - 1]); } PDFExportContext.AddParameter("EXPORTFILE", "$(DOC)" + @"\" + "$(PROJECTNAME)"); PDFExportContext.AddParameter("EXPORTSCHEME", "EPLAN_default_value"); new CommandLineInterpreter().Execute("export", PDFExportContext); } catch (System.Exception ex1) { MessageBox.Show("Error", ex1.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } } #endregion //////////////////////////////////////////SCRIPT STAMPARE FINE }