312 lines
11 KiB
C#
312 lines
11 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 ExtendedInfoBox : 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
|
|
|
|
static ExtendedInfoBox()
|
|
{
|
|
SetDllInfo(); //Name, Version und Copyright der DLL setzen
|
|
}
|
|
|
|
public ExtendedInfoBox(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
|
|
}
|
|
|
|
private void ExtendedInfoBox_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
search1.SetSearchText(textBoxText.Text); //Text aus der Textbox übergeben
|
|
search1.RefreshDisplay += new Search.RefreshDelegate(RefreshDisplay); //Hier wird das Event abonniert
|
|
search1.InputChanged += new Search.InputChangedDelegate(InputChanged); //Hier wird das Event abonniert
|
|
|
|
replace1.SetSearchText(textBoxText.Text); //Text aus der Textbox übergeben
|
|
replace1.StringFound += new Replace.EventDelegate(RefreshDisplay); //Hier wird das Event abonniert
|
|
}
|
|
catch (IncompleteInputException)
|
|
{
|
|
MessageBox.Show("Eingabe unvollständig!");
|
|
}
|
|
catch (StringNotMatchException)
|
|
{
|
|
MessageBox.Show("Keine (weitere) Übereinstimmung gefunden!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Available Icons
|
|
/// </summary>
|
|
public enum Icons
|
|
{
|
|
Construction,
|
|
Email,
|
|
Error,
|
|
Information,
|
|
Instruction,
|
|
Question,
|
|
Telephon,
|
|
Tips,
|
|
Warning
|
|
}
|
|
|
|
//Zeichnet die TextBox neu
|
|
void RefreshDisplay(int currentCursorPosition, int searchStringLenght)
|
|
{
|
|
RefreshTextBox(currentCursorPosition, searchStringLenght); //Ansicht aktualisieren
|
|
}
|
|
|
|
//Trifft zu wenn sich die Eingabe geändert hat
|
|
void InputChanged()
|
|
{
|
|
replace1.SetMoreMatch(true); //Gibt der Replace Funktion bekannt, dass es weitere Treffer gibt
|
|
}
|
|
|
|
private void RefreshTextBox(int currentCursorPosition, int searchStringLenght)
|
|
{
|
|
//Ansicht aktualisieren
|
|
textBoxText.Text = search1.GetSearchText(); //Aktuellen Text zuweisen
|
|
textBoxText.Focus(); //Focus auf die Textbox
|
|
textBoxText.Select(currentCursorPosition, searchStringLenght); //Suchstring in der Textbox selektieren
|
|
textBoxText.Refresh();
|
|
}
|
|
|
|
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
|
|
textBoxText.Text = text; //Text schreiben
|
|
}
|
|
|
|
private string ExportText()
|
|
{
|
|
if (textBoxText.SelectionLength > 0)
|
|
{
|
|
return textBoxText.SelectedText; //Gibt den selektierten Text zurück
|
|
}
|
|
else
|
|
{
|
|
return FixLineLenght.Format(textBoxText.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);
|
|
}
|
|
|
|
private List<int> FindPositionsOfText(string textToFind, string textToSearch)
|
|
{
|
|
//Wenn der Suchstring noch leer ist, dann die Methode verlassen, weil sonst endlos gesucht wird
|
|
if (String.IsNullOrEmpty(textToFind))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
List<int> result = new List<int>();
|
|
|
|
int lastIndex = 0;
|
|
while (textToSearch.IndexOf(textToFind, lastIndex) > -1)
|
|
{
|
|
result.Add(textToSearch.IndexOf(textToFind, lastIndex));
|
|
lastIndex = result[result.Count - 1] + textToFind.Length;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|