using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Eugen.ESystem.Windows.Forms
{
public partial class InfoBox : Form
{
#region Version und Copyright
// Version und Copyright
string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
//Assembly Datum und Zeit
static DateTime value = AssemblyDateTime();
string date = value.ToShortDateString();
string time = value.ToLongTimeString();
private static DateTime AssemblyDateTime()
{
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
//Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original)
return buildDateTime;
}
#endregion
#region DLL-Info
///
/// Contains the name of the dll file.
///
public static string DllName { private set; get; }
///
/// Contains the version of the dll file.
///
public static string DllVersion { private set; get; }
///
/// Contains the copyright notice.
///
public static string Copyright { private set; get; }
///
/// Contains the name-, version- and copyright-information of the dll file.
///
public static string[] DllInfo { private set; get; }
private void SetDllInfo()
{
//Name, Version und Copyright setzen
DllName = dllName;
DllVersion = dllVersion;
Copyright = this.copyright;
string[] dllInfo = new string[3];
dllInfo[0] = dllName;
dllInfo[1] = dllVersion;
dllInfo[2] = this.copyright;
DllInfo = dllInfo;
}
#endregion
public InfoBox(string windowTitle, Icons icon, string title, string headerRow1, string headerRow2, string headerRow3, string text, bool export)
{
SetDllInfo(); //Name, Version und Copyright der DLL setzen
InitializeComponent();
SetContent(windowTitle, icon, title, headerRow1, headerRow2, headerRow3, text, export); //Fensterinhalt setzen
}
///
/// Available Icons
///
public enum Icons
{
Construction,
Email,
Error,
Information,
Instruction,
Question,
Telephon,
Tips,
Warning
}
private void buttonClose1_Click(object sender, EventArgs e)
{
this.Close();
}
private void buttonClose2_Click(object sender, EventArgs e)
{
this.Close();
}
private void buttonExport_Click(object sender, EventArgs e)
{
//Speichert den Inhalt der TextBox oder den selektierten Bereich daraus
saveFileDialog.Filter = Language.dialog001;
saveFileDialog.ShowDialog();
}
private void saveFileDialog_FileOk(object sender, CancelEventArgs e)
{
string fileName = saveFileDialog.FileName;
string text = ExportText();
try
{
File.WriteAllText(fileName, text); //Schreibt den Text in eine Datei
}
catch (Exception)
{
MessageBox.Show(Language.message001,
Language.messageHead001,
MessageBoxButtons.OK,
MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1);
}
}
private void SetContent(string windowTitle, Icons icon, string title, string headerRow1, string headerRow2, string headerRow3, string text, bool export)
{
//Export Button freischalten oder nicht
if (export)
{
buttonExport.Visible = true;
buttonClose1.Visible = true;
buttonClose2.Visible = false;
}
else
{
buttonExport.Visible = false;
buttonClose1.Visible = false;
buttonClose2.Visible = true;
}
//Icon setzen
switch (icon)
{
case Icons.Construction:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Construction;
break;
case Icons.Email:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Email;
break;
case Icons.Error:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Error;
break;
case Icons.Information:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Information;
break;
case Icons.Instruction:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Instruction;
break;
case Icons.Question:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Question;
break;
case Icons.Telephon:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Telephone;
break;
case Icons.Tips:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Tips;
break;
case Icons.Warning:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Warning;
break;
default:
this.pictureBox.Image = global::Eugen.ESystem.Windows.Forms.Pictures.Information;
break;
}
this.Text = windowTitle; //Fenster Titel
labelTitle.Text = title; //Titel schreiben
labelHeaderRow1.Text = headerRow1; //Header Zeile 1 schreiben
labelHeaderRow2.Text = headerRow2; //Header Zeile 2 schreiben
labelHeaderRow3.Text = headerRow3; //Header Zeile 3 schreiben
textBox.Text = text; //Text schreiben
}
private string ExportText()
{
if (textBox.SelectionLength > 0)
{
return textBox.SelectedText; //Gibt den selektierten Text zurück
}
else
{
return FixLineLenght.Format(textBox.Text, 80); //Gibt den ganzen Text formatiert zurück
}
}
///
/// Sets a user specific window size.
///
/// A value greater than 400.
/// A value greater than 300.
public void SetSize(int width, int height)
{
this.ClientSize = new System.Drawing.Size(width - 8, height - 31);
}
}
}