198 lines
5.8 KiB
C#
198 lines
5.8 KiB
C#
using KlassenBIB;
|
|
using Microsoft.Win32;
|
|
using SanShared;
|
|
using SanSystem.Einstellungen;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SanSystem
|
|
{
|
|
class Global
|
|
{
|
|
public event EventHandler RequestBuildNewLinerReste;
|
|
public event EventHandler OnStatusMessageChanged;
|
|
public static readonly Global instance = new Global();
|
|
|
|
|
|
|
|
const string userroot = "HKEY_CURRENT_USER\\Software";
|
|
const string firmkey = "Cosysda";
|
|
const string subkey = "SanManager";
|
|
const string speicherpfad_to_projekts = "projekte";
|
|
private readonly string programmversion = string.Empty;
|
|
|
|
public string AktuelleBesatzung = string.Empty;
|
|
|
|
string projektpfad = "18-850";
|
|
|
|
string statusMessage = "";
|
|
|
|
|
|
|
|
public string StatusMessage
|
|
{
|
|
get
|
|
{
|
|
return statusMessage;
|
|
}
|
|
set
|
|
{
|
|
if (statusMessage == value) return;
|
|
statusMessage = value;
|
|
StatusMessageChanged(EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public CSVParser.AcceptedCSVFormats AnlageType = CSVParser.AcceptedCSVFormats.BLUELIGHT;
|
|
|
|
public void StatusMessageChanged(EventArgs args)
|
|
{
|
|
EventHandler handler = OnStatusMessageChanged;
|
|
if (handler != null)
|
|
handler(this, args);
|
|
}
|
|
|
|
public void BuildNewLinerReste(EventArgs args)
|
|
{
|
|
EventHandler handler = RequestBuildNewLinerReste;
|
|
if (handler != null)
|
|
handler(this, args);
|
|
}
|
|
|
|
public string PROGRAMMVERSION
|
|
{
|
|
get
|
|
{
|
|
string version = string.Empty;
|
|
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SanSystem." + "version.txt"))
|
|
{
|
|
using (StreamReader reader = new StreamReader(stream))
|
|
{
|
|
version = reader.ReadToEnd();
|
|
}
|
|
}
|
|
|
|
return version;
|
|
}
|
|
}
|
|
|
|
public string ProjektNummer
|
|
{
|
|
get
|
|
{
|
|
return projektpfad;
|
|
}
|
|
set
|
|
{
|
|
projektpfad = value;
|
|
}
|
|
}
|
|
|
|
public string Projektpfad
|
|
{
|
|
get
|
|
{
|
|
return "C:\\";// Path.Combine(Properties.Settings.Default.DATABASEMAIN,speicherpfad_to_projekts, projektpfad);
|
|
}
|
|
}
|
|
|
|
public static Global Instance
|
|
{
|
|
get
|
|
{
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
public void ChangeProjekt(string projektnummer)
|
|
{
|
|
Database.Datenbank.Instance.SaveProjekt();
|
|
this.ProjektNummer = projektnummer;
|
|
Database.Datenbank.Instance.loadedProjekt = null;
|
|
|
|
string pfad = Path.Combine(Projektpfad);
|
|
if (!Directory.Exists(pfad)) Directory.CreateDirectory(pfad);
|
|
Database.Datenbank.Instance.LoadProjekt(ProjektNummer);
|
|
}
|
|
|
|
void LadeRegistry()
|
|
{
|
|
/*string key = "NjAwNjQzQDMxMzkyZTM0MmUzMG5La2UzQ1F0R3dFZEh5VWtGazZ0aHpUWi9XdkxJT2xCbktXRXFWc0ZsdzA9";
|
|
byte[] s = Encoding.ASCII.GetBytes(key);
|
|
var i = BitConverter.ToString(s);
|
|
Trace.WriteLine(i.ToString());
|
|
*/
|
|
|
|
string keyName = userroot + "\\" + firmkey + "\\" + subkey;
|
|
|
|
string lastProjektNummer = "";
|
|
|
|
string vorarbeiter = "";
|
|
string helfer = "";
|
|
try
|
|
{
|
|
if(Registry.GetValue(keyName,"LastProjekt","") != null)
|
|
lastProjektNummer = Registry.GetValue(keyName, "LastProjekt", "").ToString();
|
|
if (Registry.GetValue(keyName, "Vorarbeiter", "") != null)
|
|
vorarbeiter = Registry.GetValue(keyName, "Vorarbeiter", "").ToString();
|
|
if (Registry.GetValue(keyName, "Helfer", "") != null)
|
|
helfer = Registry.GetValue(keyName, "Helfer", "").ToString();
|
|
ProjektNummer = lastProjektNummer;
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
if(vorarbeiter != "")
|
|
{
|
|
AktuelleBesatzung = string.Format("{0} / {1}", vorarbeiter, helfer);
|
|
}
|
|
}
|
|
|
|
void SpeicherInRegistry()
|
|
{
|
|
string keyName = userroot + "\\" + firmkey + "\\" + subkey;
|
|
Registry.SetValue(keyName, "LastProjekt", ProjektNummer);
|
|
string[] besatzung = AktuelleBesatzung.Split('/');
|
|
if(besatzung.Length >0)
|
|
{
|
|
Registry.SetValue(keyName, "Vorarbeiter", besatzung[0]);
|
|
if(besatzung.Length > 1)
|
|
{
|
|
Registry.SetValue(keyName, "Helfer", besatzung[1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool CheckNetworkAnlageAvaible()
|
|
{
|
|
Ping pingSender = new Ping();
|
|
PingOptions options = new PingOptions();
|
|
SoftwareConfiguration softwareConfiguration = new SoftwareConfiguration();
|
|
|
|
string data = "aaaaaaaaaaaaa";
|
|
byte[] buffer = Encoding.ASCII.GetBytes(data);
|
|
int timeout = 20;
|
|
PingReply reply = pingSender.Send(softwareConfiguration.GetAnlageIP(), timeout, buffer, options);
|
|
return reply.Status == IPStatus.Success;
|
|
|
|
}
|
|
|
|
public Global()
|
|
{
|
|
LadeRegistry();
|
|
}
|
|
|
|
~Global()
|
|
{
|
|
SpeicherInRegistry();
|
|
}
|
|
}
|
|
}
|