time_dll_visualstudio/Test_Time/Form1.cs
Hoeglinger Eugen c600341af5 Initialized
- Klassenbibliothek zum ausgeben von Tag, Datum, Zeit und zum Stoppen
2022-05-16 16:10:28 +02:00

182 lines
6.8 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;
using Eugen.ESystem;
namespace Test_Time
{
public partial class Form1 : Form
{
#region Version und Copyright
// Version und Copyright
string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
static object[] attributes = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
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 = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
//return startYear.Remove(0, startYear.LastIndexOf(" ") + 1);
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 String.Concat(((AssemblyCopyrightAttribute)attributes[0]).Copyright, "-", currentYear);
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear));
}
}
#endregion
#region Programm-Info
/// <summary>
/// Contains the name of the program file
/// </summary>
public static string ProgramName { set; get; }
/// <summary>
/// Contains the version of the program file
/// </summary>
public static string ProgramVersion { set; get; }
/// <summary>
/// Contains the copyright notice
/// </summary>
public static string Copyright { set; get; }
private void SetProgramInfo()
{
//Name, Version und Copyright setzen
ProgramName = programName;
ProgramVersion = programVersion;
Copyright = copyright;
}
#endregion
public Form1()
{
SetProgramInfo();
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
labelProgramInfo.Text = String.Concat(ProgramName, "\r\n", ProgramVersion, "\r\n", Copyright); // Zeigt die Programm-Information an
labelDLLInfo.Text = String.Concat(Time.DllName, "\r\n", Time.DllVersion, "\r\n", Time.Copyright); // Zeigt die DLL-Information an
}
private void buttonShowCurrentDay_Click(object sender, EventArgs e)
{
labelResult.Text = String.Concat("The current date is ", Time.CurrentDay());
}
private void buttonShowcurrentDate_Click(object sender, EventArgs e)
{
labelResult.Text = String.Concat("The current date is ", Time.CurrentDate());
}
private void buttonShowCurrentTime_Click(object sender, EventArgs e)
{
labelResult.Text = Time.CurrentTime(Time.WriteMillisecond.No);
}
private void buttonShowCurrentTimeMs_Click(object sender, EventArgs e)
{
labelResult.Text = Time.CurrentTime(Time.WriteMillisecond.Yes);
}
private void buttonShowDateAndTime_Click(object sender, EventArgs e)
{
labelResult.Text = Time.CurrentDateAndTime(Time.WriteMillisecond.No);
}
private void buttonShowDateAndTimeMs_Click(object sender, EventArgs e)
{
labelResult.Text = Time.CurrentDateAndTime(Time.WriteMillisecond.Yes);
}
private void buttonCurrentDayDateTime_Click(object sender, EventArgs e)
{
labelResult.Text = Time.CurrentDayDateTime();
}
Time.StopWatch stopWatch = new Time.StopWatch();
private void buttonStartTime_Click(object sender, EventArgs e)
{
stopWatch.Start();
labelResult.Text = String.Concat("Stop Watch started at ", Time.CurrentTime(Time.WriteMillisecond.Yes));
}
private void buttonStopTime_Click(object sender, EventArgs e)
{
stopWatch.Stop();
labelResult.Text = String.Concat("Stop Watch stoped at ", Time.CurrentTime(Time.WriteMillisecond.Yes));
}
private void buttonShowDuration_Click(object sender, EventArgs e)
{
string durationtime = stopWatch.DurationTime();
if (String.IsNullOrEmpty(durationtime))
{
MessageBox.Show("The stopwatch must be stopped before\n\rthe duration time can be calculated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
labelResult.Text = String.Concat("The duraton time is ", durationtime);
}
}
}
}