168 lines
6.0 KiB
C#
168 lines
6.0 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.Resources;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Eugen.ESystem.Windows.Forms
|
|
{
|
|
public partial class AboutBox : 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
|
|
/// <summary>
|
|
/// Contains the name of the dll file.
|
|
/// </summary>
|
|
public static string DllName { private set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the version of the dll file.
|
|
/// </summary>
|
|
public static string DllVersion { private set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the copyright notice.
|
|
/// </summary>
|
|
public static string Copyright { private set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the name-, version- and copyright-information of the dll file.
|
|
/// </summary>
|
|
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 AboutBox(string programName, string programVersion, string programCopyright)
|
|
{
|
|
SetDllInfo(); //Name, Version und Copyright der DLL setzen
|
|
|
|
InitializeComponent();
|
|
|
|
SetContent(programName, programVersion, programCopyright); //Fensterinhalt setzen
|
|
}
|
|
|
|
protected string ProgramName { private set; get; }
|
|
protected string ProgramVersion { private set; get; }
|
|
protected string ProgramCopyright { private set; get; }
|
|
|
|
private void buttonClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close(); //Das Fenster schliessen
|
|
}
|
|
|
|
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 programName, string programVersion, string programCopyright)
|
|
{
|
|
labelProgramName.Text = programName;
|
|
ProgramName = programName;
|
|
if (programVersion.StartsWith("V"))
|
|
{
|
|
labelVersion.Text = programVersion;
|
|
ProgramVersion = programVersion;
|
|
}
|
|
else
|
|
{
|
|
labelVersion.Text = String.Concat("Version ", programVersion);
|
|
ProgramVersion = labelVersion.Text;
|
|
}
|
|
labelCopyright.Text = programCopyright;
|
|
ProgramCopyright = programCopyright;
|
|
}
|
|
|
|
private void SaveFileDialogFileOk(object sender, System.ComponentModel.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 string ExportText()
|
|
{
|
|
if (textBox.SelectionLength > 0)
|
|
{
|
|
return textBox.SelectedText; //Gibt den selektierten Text zurück
|
|
}
|
|
else
|
|
{
|
|
return String.Concat(ProgramName, "\r\n", ProgramVersion, "\r\n", ProgramCopyright, "\r\n--------------------------------------------------------------------------------\r\n", FixLineLenght.Format(textBox.Text, 80)); //Gibt den ganzen Text zurück
|
|
}
|
|
}
|
|
}
|
|
}
|