265 lines
9.6 KiB
C#
265 lines
9.6 KiB
C#
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
|
|
static string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
|
static string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
static string copyright = GenerateCopyright();
|
|
string icon = Application.StartupPath + "\\Info.bmp";
|
|
//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;
|
|
}
|
|
|
|
private static string CurrentYear()
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
|
|
private static string StartYear()
|
|
{
|
|
string startYear = "";
|
|
if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © "))
|
|
{
|
|
startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", "");
|
|
while (startYear.StartsWith(" "))
|
|
{
|
|
startYear = startYear.Remove(0, 1);
|
|
}
|
|
startYear = startYear.Remove(startYear.IndexOf(" "));
|
|
return startYear;
|
|
}
|
|
else
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
}
|
|
|
|
private static string GenerateCopyright()
|
|
{
|
|
string startYear = StartYear();
|
|
string currentYear = CurrentYear();
|
|
|
|
if (startYear == currentYear)
|
|
{
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
}
|
|
else
|
|
{
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region DLL-Info
|
|
/// <summary>
|
|
/// Contains the name of the program file
|
|
/// </summary>
|
|
public static string DllName { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the version of the program file
|
|
/// </summary>
|
|
public static string DllVersion { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the copyright notice
|
|
/// </summary>
|
|
public static string Copyright { set; get; }
|
|
|
|
private static void SetDllInfo()
|
|
{
|
|
//Name, Version und Copyright setzen
|
|
DllName = dllName;
|
|
DllVersion = dllVersion;
|
|
Copyright = copyright;
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Displays a self-defined information box
|
|
/// </summary>
|
|
static InfoBox()
|
|
{
|
|
SetDllInfo(); //Name, Version und Copyright der DLL setzen
|
|
}
|
|
|
|
/// <summary>
|
|
/// Displays a self-defined information box
|
|
/// </summary>
|
|
/// <param name="caption">A valid string.</param>
|
|
/// <param name="icon">The icon that is displayed.</param>
|
|
/// <param name="title">A valid string.</param>
|
|
/// <param name="headerRow1">A valid string.</param>
|
|
/// <param name="headerRow2">A valid string.</param>
|
|
/// <param name="headerRow3">A valid string.</param>
|
|
/// <param name="text">A valid string.</param>
|
|
/// <param name="export">'True' = The Export function is available. 'False' = The export function is not available.</param>
|
|
public InfoBox(string caption, Icons icon, string title, string headerRow1, string headerRow2, string headerRow3, string text, bool export)
|
|
{
|
|
SetDllInfo(); //Name, Version und Copyright der DLL setzen
|
|
|
|
InitializeComponent();
|
|
|
|
SetContent(caption, icon, title, headerRow1, headerRow2, headerRow3, text, export); //Fensterinhalt setzen
|
|
}
|
|
|
|
/// <summary>
|
|
/// Available Icons
|
|
/// </summary>
|
|
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
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets a user specific window size.
|
|
/// </summary>
|
|
/// <param name="width">A value greater than 400.</param>
|
|
/// <param name="height">A value greater than 300.</param>
|
|
public void SetSize(int width, int height)
|
|
{
|
|
this.ClientSize = new System.Drawing.Size(width - 8, height - 31);
|
|
}
|
|
}
|
|
}
|