//Version 0.1.1 14.03.2019
// CheckBox registro per pagina e tempo di registro
// Leggere la pagina o segnare nella pagina navigation => Integrazione dello script https://suplanus.de/selectionset-pages/ (Johann Weiher)
using System.Windows.Forms;
using Eplan.EplApi.Scripting;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
public partial class EPlanP8LogBuch : System.Windows.Forms.Form
{
private TextBox LogBookText;
private Label ProjectName;
private Button LeaveMaskButton;
private Button LOGBOOKWRITE;
private TextBox LogBookCommentText;
public string sProjectpathLogBook;
private CheckBox checkPage;
private CheckBox checkTime;
#region Vom Windows Form-Designer generierter Code
///
/// Variabile designer richiesta.
///
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.LogBookCommentText = new System.Windows.Forms.TextBox();
this.checkPage = new System.Windows.Forms.CheckBox();
this.checkTime = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// LogBookText
//
this.LogBookText.Location = new System.Drawing.Point(12, 41);
this.LogBookText.Name = "LogBookText";
this.LogBookText.Size = new System.Drawing.Size(651, 20);
this.LogBookText.TabIndex = 2;
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 = 8;
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 = 7;
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 = 6;
this.LOGBOOKWRITE.Tag = "";
this.LOGBOOKWRITE.Text = "Salva";
this.LOGBOOKWRITE.UseVisualStyleBackColor = true;
this.LOGBOOKWRITE.Click += new System.EventHandler(this.LOGBOOKWRITE_Click);
//
// LogBookCommentText
//
this.LogBookCommentText.Location = new System.Drawing.Point(12, 81);
this.LogBookCommentText.Name = "LogBookCommentText";
this.LogBookCommentText.Size = new System.Drawing.Size(651, 60);
this.LogBookCommentText.TabIndex = 2;
this.LogBookCommentText.Text = "Cosa è cambiato?";
this.LogBookCommentText.Click += new System.EventHandler(this.LogBookCommentText_Click);
//
// checkPage
//
this.checkPage.Checked = true;
this.checkPage.CheckState = System.Windows.Forms.CheckState.Checked;
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 = 4;
this.checkPage.Text = "Pagine";
this.checkPage.UseVisualStyleBackColor = true;
//
// checkTime
//
this.checkTime.Checked = true;
this.checkTime.CheckState = System.Windows.Forms.CheckState.Checked;
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 = 5;
this.checkTime.Text = "Log orario";
this.checkTime.UseVisualStyleBackColor = true;
//
// EPlanP8LogBuch
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
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, 150);
this.Controls.Add(this.checkTime);
this.Controls.Add(this.checkPage);
this.Controls.Add(this.LogBookCommentText);
this.Controls.Add(this.LOGBOOKWRITE);
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", // Name: Menüpunkt
"WriteLogBook", // Name: Action
"LogBuch-Eintrag schreiben", // Statustext
35381, // Menü-ID: Einfügen/Fenstermakro...
1, // 1 = hinter Menüpunkt, 0 = vor Menüpunkt
false, // Separator davor anzeigen
false // Separator dahinter anzeigen
);
return;
}
#endregion
#region Eingabemaske EPlanP8LogBuch / Form
private void EPlanP8LogBuch_Load(object sender, EventArgs e)
{
//Prüfen ob eine LogBuch-Datei schon existiert
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
{
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 == "Was wurde geändert?")
{
LogBookCommentText.Text = "";
}
string user = Environment.UserName;
using (StreamWriter w = File.AppendText(sProjectpathLogBook))
{
Log(LogBookText.Text, LogBookCommentText.Text, user, w);
}
using (StreamReader r = File.OpenText(sProjectpathLogBook))
{
DumpLog(r);
}
this.Close ();
}
}
public void Log(string logMessage, string logComment, string loguser, TextWriter w)
{
w.Write("\r\nUltima 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");
w.WriteLine("{0}", logMessage);
w.WriteLine("\n");
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("\n");
w.WriteLine("Pagina: {0}", page);
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
w.WriteLine("\n");
w.WriteLine("-------------------------------");
}
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 == "Was wurde geändert?")
{
LogBookCommentText.SelectAll();
}
}
#endregion
}