//#################################################################################################################################
//Betron Control Systems GmbH / Großer Teil 8 / 32130 Enger / www.betron.de
//
//Autor: Andrej Robert (Entwicklung & Konstruktion)
//
//Programm: LogBuch führen
//#################################################################################################################################
//Version 0.1 29.08.2018
//Prüfung & Erstellung einer txt-Datei im DOC Ordner
//Eingabe und Kommentar Tab-getrennt
//Bestehendes Menü erweitert: STRG + L
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;
#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.LogBookCommentText = new System.Windows.Forms.TextBox();
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 = 1;
this.LogBookText.Text = "Eingabezeile";
this.LogBookText.Click += new System.EventHandler(this.LogBookText_Click);
//
// 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 = 4;
this.LeaveMaskButton.Text = "Abbrechen";
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 = 3;
this.LOGBOOKWRITE.Tag = "";
this.LOGBOOKWRITE.Text = "Eintrag schreiben";
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, 20);
this.LogBookCommentText.TabIndex = 2;
this.LogBookCommentText.Text = "Kommentarzeile";
this.LogBookCommentText.Click += new System.EventHandler(this.LogBookCommentText_Click);
//
// 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, 161);
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 = "LogBuch";
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(
"LogBuch", // 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)" + @"\LogBuch.txt");
if (!File.Exists(sProjectpathLogBook))
{
DialogResult Result = MessageBox.Show("LogBuch-Datei für diese Projekt existiert nicht!\nAnlegen?", "Information", 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 = "Eintrag für: " + 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 == "Eingabezeile")
{
DialogResult Result = MessageBox.Show("Kein Eintrag!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
if (LogBookCommentText.Text == "Kommentarzeile")
{
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 static void Log(string logMessage, string logComment, string loguser, TextWriter w)
{
w.Write("\r\nLog Entry : ");
w.WriteLine("{0} {1} \tBearbeiter: {2}", DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString(),
loguser);
w.WriteLine("\n");
w.WriteLine("{0}\tKommentar: {1}", logMessage, logComment);
//alternative untereinander
//w.WriteLine("{0}", logMessage);
//w.WriteLine("Kommentar: {0}",logComment);
w.WriteLine("-------------------------------");
}
public static void DumpLog(StreamReader r)
{
string line;
while ((line = r.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
#endregion
#region TextBox-Felder markieren
private void LogBookText_Click(object sender, EventArgs e)
{
if (LogBookText.Text == "Eingabezeile")
{
LogBookText.SelectAll();
}
}
private void LogBookCommentText_Click(object sender, EventArgs e)
{
if (LogBookCommentText.Text == "Kommentarzeile")
{
LogBookCommentText.SelectAll();
}
}
#endregion
}