301 lines
9.8 KiB
C#
301 lines
9.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.IO;
|
|
using static Eugen.ESystem.IO.LoadXMLFile;
|
|
|
|
namespace Test_LoadXMLFile
|
|
{
|
|
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 = 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(LoadXMLFile.DllName, "\r\n", LoadXMLFile.DllVersion, "\r\n", LoadXMLFile.Copyright); // Zeigt die DLL-Information an
|
|
}
|
|
|
|
private void buttonShowInfo_Click(object sender, EventArgs e)
|
|
{
|
|
var load = new LoadXMLFile();
|
|
load.FileName = @"H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LoadXMLFile.git\Daten\Management.xml";
|
|
//load.FileName = @"H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LoadXMLFile.git\Daten\NXenvironment_NX 1953_CAD.xml";
|
|
load.Topic = "NX-Portal";
|
|
load.Group = "Management";
|
|
load.Key = "Method";
|
|
//load.LoadAllValues = LoadXMLFile.LoadAll.Yes; //Es werden alle Elemente geladen
|
|
//load.LoadAllValues = LoadXMLFile.LoadAll.No; //Es werden nur die Elemente geladen, die unter 'Group' gespeichert sind
|
|
//load.Load();
|
|
|
|
if (checkBoxLoadAllValues.Checked)
|
|
{
|
|
load.LoadAllValues = LoadXMLFile.LoadAll.Yes; //Es werden alle Elemente geladen
|
|
load.Load();
|
|
|
|
if (load.Values != null)
|
|
{
|
|
labelResult1.Text = Ausgabe("Yes", load.FileName, load.Topic, load.Group, load.Key, load.Values);
|
|
labelResult2.Text = "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
load.LoadAllValues = LoadXMLFile.LoadAll.No; //Es werden nur die Elemente geladen, die unter 'Group' gespeichert sind
|
|
load.Load();
|
|
|
|
if (load.Values != null)
|
|
{
|
|
labelResult1.Text = Ausgabe1(load.FileName, load.Topic, load.Group, load.Key, load.Values);
|
|
}
|
|
|
|
//Neue Gruppe setzen
|
|
load.Group = "NX";
|
|
load.Key = "Version";
|
|
load.Load();
|
|
|
|
if (load.Values != null)
|
|
{
|
|
labelResult2.Text = Ausgabe2(load.Group, load.Key, load.Values);
|
|
}
|
|
else
|
|
{
|
|
labelResult1.Text = "Keine Werte";
|
|
labelResult2.Text = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
private string Ausgabe(string loadAll, string fileName, string topic, string group, string key, string[,] values)
|
|
{
|
|
string result = "";
|
|
|
|
result = "Filename: " + fileName;
|
|
result += "\r\nTopic: " + topic;
|
|
result += "\r\nLoad all values: " + loadAll;
|
|
result += "\r\n\r\nValues (Group - ID - Key - Keyvalue - Standard): ";
|
|
|
|
int z = 0;
|
|
|
|
foreach (var item in values)
|
|
{
|
|
if (z == 5)
|
|
{
|
|
z = 0;
|
|
}
|
|
if (z == 4)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 3)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 2)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 1)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 0)
|
|
{
|
|
result += "\r\n" + item;
|
|
z++;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private string Ausgabe1(string fileName, string topic, string group, string key, string[,] values)
|
|
{
|
|
string result = "";
|
|
|
|
result = "Filename: " + fileName;
|
|
result += "\r\nTopic: " + topic;
|
|
result += "\r\n\r\nGroup: " + group;
|
|
result += "\r\nKey: " + key;
|
|
result += "\r\n\r\nValues (ID - Management - Standard): ";
|
|
|
|
int z = 0;
|
|
|
|
foreach (var item in values)
|
|
{
|
|
if (z == 4)
|
|
{
|
|
z = 0;
|
|
}
|
|
if (z == 3)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 2)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 1)
|
|
{
|
|
result += "\r\n" + item;
|
|
z++;
|
|
}
|
|
if (z == 0)
|
|
{
|
|
z++;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private string Ausgabe2(string group, string key, string[,] values)
|
|
{
|
|
string result = "";
|
|
|
|
result += "\r\n\r\nGroup: " + group;
|
|
result += "\r\nKey: " + key;
|
|
result += "\r\n\r\nValues (ID - Version - Standard): ";
|
|
|
|
int z = 0;
|
|
|
|
foreach (var item in values)
|
|
{
|
|
if (z == 4)
|
|
{
|
|
z = 0;
|
|
}
|
|
if (z == 3)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 2)
|
|
{
|
|
result += " - " + item;
|
|
z++;
|
|
}
|
|
if (z == 1)
|
|
{
|
|
result += "\r\n" + item;
|
|
z++;
|
|
}
|
|
if (z == 0)
|
|
{
|
|
z++;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|