525 lines
19 KiB
C#
525 lines
19 KiB
C#
using DatenDB;
|
|
using Deckungsbeitrag.AA_Forms;
|
|
using Deckungsbeitrag.Properties;
|
|
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Management;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using System.Web.UI.WebControls.WebParts;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Deckungsbeitrag
|
|
{
|
|
static class Program
|
|
{
|
|
public static ImageList imagelist = new ImageList();
|
|
public static string userid;
|
|
public static bool Artikelliste_Importiert = false;
|
|
public static bool Kundenliste_Importiert = false;
|
|
public static bool Software_Updated = false;
|
|
private static DateTime zielZeit = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 22, 0, 0);
|
|
private static System.Timers.Timer timer;
|
|
|
|
private static bool istest = false;
|
|
/// <summary>
|
|
/// Der Haupteinstiegspunkt für die Anwendung.
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main()
|
|
{
|
|
userid = ConfigurationManager.AppSettings["ConnectionString"].Split(';')[0];
|
|
userid = userid.Split('=')[1];
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Screen[] screens = Screen.AllScreens;
|
|
timer.Interval = 1000;
|
|
timer.Elapsed += Timer_Elapsed;
|
|
timer.Start();
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
// Check, Install und Update wenn Update vorhanden.
|
|
if (CheckAndInstallUpdate())
|
|
{
|
|
MessageBox.Show("Update wurde erfolgreich durchgeführt.", "UPDATE INFO",MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
Software_Updated = true;
|
|
Settings.Default.LastSoftwareUpdate = DateTime.Now;
|
|
return;
|
|
}
|
|
|
|
// Laden der Image-Liste mit Icons für ObjectListView in Export etc.
|
|
ImageList_Laden();
|
|
|
|
// Importieren und Updaten der Kundenliste wenn Datei vorhanden.
|
|
KundenList_Laden();
|
|
|
|
// Importieren und Updaten der Artikelliste wenn Datei vorhanden.
|
|
ArtikelList_Laden();
|
|
|
|
Settings.Default.Save();
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
if (istest) { Application.Run(new FormAufleger()); return; }
|
|
|
|
if (userid.StartsWith("ms") | userid.StartsWith("ps"))
|
|
{
|
|
if (userid.Contains("wstrasse")) Application.Run(new FormAufleger(userid));
|
|
else Application.Run(new FormFehlmengeCount(userid));
|
|
}
|
|
else
|
|
{
|
|
// Öffnen der ReadMe wenn noch nicht geöffnet wurde.
|
|
Open_ReadMe();
|
|
|
|
FormLogin loginForm = new FormLogin();
|
|
if (loginForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
// Switch on BenutzerRolle für Weiterleitung zum richtigen Screen
|
|
switch (loginForm.Person.Rolle)
|
|
{
|
|
case BenutzerRolle.Verwaltung: //Büropersonal ohne aktive Hallenbeschäftigung
|
|
Application.Run(new FormMain(loginForm.Person));
|
|
break;
|
|
case BenutzerRolle.Fahrer: //Zustellfahrer
|
|
Application.Run(new FormMain(loginForm.Person));
|
|
break;
|
|
case BenutzerRolle.Admin: //Höheres Büropersonal oder Claudia und Kevin
|
|
Application.Run(new FormMain(loginForm.Person));
|
|
break;
|
|
case BenutzerRolle.Waschstrasse: //Bediener einer Waschstraße
|
|
Application.Run(new FormNeuerAuftrag(loginForm.Person, AuftragTyp.Standart));
|
|
break;
|
|
case BenutzerRolle.Master: //Entwickler oder Claudia und Kevin
|
|
Application.Run(new FormMain(loginForm.Person));
|
|
break;
|
|
case BenutzerRolle.Expedit: //Endkontrolle Lieferungen und Lieferscheine (Mirka)
|
|
Application.Run(new FormExpedit(loginForm.Person, screens));
|
|
break;
|
|
case BenutzerRolle.Frottee: //Containerbestückung Frotteewäsche
|
|
//BenutzerRolle Frottee = Expedit Frottee da die Maschine keine Anmeldung erfordert.
|
|
Application.Run(new FormExpedit(loginForm.Person, screens));
|
|
break;
|
|
case BenutzerRolle.Flach: //Containerbestückung Flachwäsche
|
|
//BenutzerRolle Flach = Expedit Frottee da die Maschine keine Anmeldung erfordert.
|
|
Application.Run(new FormExpedit(loginForm.Person, screens));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
|
{
|
|
if (DateTime.Now >= zielZeit)
|
|
{
|
|
timer.Stop();
|
|
timer.Dispose();
|
|
Application.Exit(); // Schließt alle Forms und beendet die App
|
|
}
|
|
}
|
|
|
|
private static void ArtikelList_Laden()
|
|
{
|
|
string updatePath = @"N:\TECHNIK\Software\Wirl-Verwaltung\Listen"; //Pfad zu Listen
|
|
string dateiName = "Artikelkurzliste.csv";
|
|
string row;
|
|
string[] rows;
|
|
|
|
try
|
|
{
|
|
if (File.Exists(Path.Combine(updatePath, dateiName)))
|
|
{
|
|
string filename = Path.Combine(updatePath, dateiName);
|
|
StreamReader streamReader = new StreamReader(filename, Encoding.GetEncoding("iso-8859-1"));
|
|
row = string.Empty;
|
|
rows = new string[0];
|
|
int saved = 0;
|
|
int tosave = 0;
|
|
int idx = 1;
|
|
|
|
while (!streamReader.EndOfStream)
|
|
{
|
|
Array.Resize<string>(ref rows, idx);
|
|
row = streamReader.ReadLine();
|
|
if (row.StartsWith("60") || row.StartsWith("20"))
|
|
{
|
|
rows[idx - 1] = row;
|
|
idx++;
|
|
}
|
|
}
|
|
streamReader.Close();
|
|
|
|
foreach (string line in rows)
|
|
{
|
|
string[] linedata = line.Split(';');
|
|
|
|
if (linedata[0] == "60" || linedata[0] == "20")
|
|
{
|
|
tosave++;
|
|
|
|
Artikel art = Artikel.GetArtikel(Convert.ToInt32(linedata[1]));
|
|
if (art == null) art = new Artikel();
|
|
|
|
art.Nummer = Convert.ToInt32(linedata[1]);
|
|
art.Bezeichnung = linedata[3];
|
|
|
|
switch (art.Nummer)
|
|
{
|
|
case var nr when nr.ToString()[1] == '3':
|
|
art.Kategorie = ArtikelKategorie.Frottee;
|
|
break;
|
|
case var nr when nr.ToString()[1] == '1' & nr.ToString()[2] == '1':
|
|
if (nr.ToString()[4] == '5' || nr.ToString()[4] == '6')
|
|
art.Kategorie = ArtikelKategorie.Spannleintuch;
|
|
else art.Kategorie = ArtikelKategorie.Grossteile;
|
|
break;
|
|
case var nr when nr.ToString()[1] == '1' & nr.ToString()[2] == '2':
|
|
art.Kategorie = ArtikelKategorie.Kleinteile;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
//Erstellen der Shortbezeichnung für Buttons
|
|
if (art.Bezeichnung.Contains("DOPPEL") | art.Bezeichnung.Contains("D-")) art.Short = art.Short + "D-";
|
|
if (art.Bezeichnung.Contains("SPANN")) art.Short = art.Short + "SP";
|
|
if (art.Bezeichnung.Contains("LEINTUCH")) art.Short = art.Short + "LT";
|
|
if (art.Bezeichnung.Contains("SPANN"))
|
|
{
|
|
string[] s = art.Bezeichnung.Split(' ');
|
|
if (s.Length == 3) art.Short = art.Short + " " + s[2];
|
|
} //Farben zuordnen und zu Short hinzufügen
|
|
if (art.Bezeichnung.Contains("HANDTUCH")) art.Short = art.Short + "HT";
|
|
if (art.Bezeichnung.Contains("DUSCHTUCH")) art.Short = art.Short + "DT";
|
|
if (art.Bezeichnung.Contains("BADETUCH")) art.Short = art.Short + "BT";
|
|
if (art.Bezeichnung.Contains("BADEVORLEGER")) art.Short = art.Short + "BV";
|
|
if (art.Bezeichnung.Contains("BADEMANTEL")) art.Short = art.Short + "BM";
|
|
if (art.Bezeichnung.Contains("SAUNATUCH")) art.Short = art.Short + "ST";
|
|
if (art.Bezeichnung.Contains("GESICHTSTUCH")) art.Short = art.Short + "GT";
|
|
if (art.Bezeichnung.Contains("POLSTERBEZUG"))
|
|
{
|
|
string extra;
|
|
int index = art.Bezeichnung.IndexOf(" ") + 1;
|
|
int length = art.Bezeichnung.IndexOf(" ", index + 1) - index;
|
|
|
|
art.Short = art.Short + "PB";
|
|
if (index > 0 & length > 0)
|
|
{
|
|
extra = art.Bezeichnung.Substring(index, length);
|
|
art.Short += " " + extra;
|
|
}
|
|
|
|
switch (art.Bezeichnung)
|
|
{
|
|
case var bez when bez.Contains("60x80"):
|
|
art.Short = art.Short + " 60x80";
|
|
break;
|
|
case var bez when bez.Contains("40x60"):
|
|
art.Short = art.Short + " 40x60";
|
|
break;
|
|
case var bez when bez.Contains("40x40"):
|
|
art.Short = art.Short + " 40x40";
|
|
break;
|
|
case var bez when bez.Contains("40x50"):
|
|
art.Short = art.Short + " 40x50";
|
|
break;
|
|
case var bez when bez.Contains("40x70"):
|
|
art.Short = art.Short + " 40x70";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} //Größen zuordnen und zu Short hinzufügen
|
|
if (art.Bezeichnung.Contains("DECKENBEZUG"))
|
|
{
|
|
string extra;
|
|
int index = art.Bezeichnung.IndexOf(" ") + 1;
|
|
int length = art.Bezeichnung.IndexOf(" ", index + 1) - index;
|
|
|
|
art.Short = art.Short + "DB";
|
|
if (index > 0 & length > 0)
|
|
{
|
|
extra = art.Bezeichnung.Substring(index, length);
|
|
art.Short += " " + extra;
|
|
}
|
|
|
|
}
|
|
if (art.Bezeichnung.Contains("TISCHTUCH"))
|
|
{
|
|
art.Short = art.Short + "TT";
|
|
int index = art.Bezeichnung.IndexOf("x");
|
|
if (index > 0) art.Short = art.Short + art.Bezeichnung.Substring(index - 4, 8);
|
|
} //Tischtücher und Größen zuordnen und zu Short hinzufügen
|
|
if (art.Bezeichnung.Contains("MUNDSERVIETTE")) art.Short = art.Short + "MS";
|
|
if (art.Bezeichnung.Contains("DECKSERVIETTE")) art.Short = art.Short + "DS";
|
|
|
|
|
|
|
|
if (art.Save() == 1) saved++;
|
|
|
|
}
|
|
}
|
|
if (saved == tosave) { Artikelliste_Importiert = true; Settings.Default.LastArtikelUpdate = DateTime.Now; }
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Import fehlgeschlagen: {ex.Message}\nPfad: {updatePath}\nDatei: {dateiName}", "IMPORT FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
finally
|
|
{
|
|
if (Artikelliste_Importiert) File.Delete(Path.Combine(updatePath, dateiName));
|
|
}
|
|
}
|
|
private static void Open_ReadMe()
|
|
{
|
|
string readmePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Verwaltung_ReadMe.txt");
|
|
// Prüfe, ob ReadMe schon einmal geöffnet wurde
|
|
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\KilianWirlGmbH\Verwaltung"))
|
|
{
|
|
if (key == null || key.GetValue("ReadMeShown") == null)
|
|
{
|
|
// Erstes Mal nach Installation
|
|
if (File.Exists(readmePath))
|
|
{
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = readmePath,
|
|
UseShellExecute = true
|
|
});
|
|
|
|
// WICHTIG: Warte 2 Sekunden (ReadMe öffnen)
|
|
System.Threading.Thread.Sleep(2000);
|
|
|
|
// Abbruch-Dialog
|
|
DialogResult result = MessageBox.Show(
|
|
"ReadMe wurde geöffnet.\n\n" +
|
|
"Falls INSTALL-REMINDER noch Änderungen enthält,\n" +
|
|
"soll die Anwendung jetzt ABGEBROCHEN werden?\n\n" +
|
|
"[JA = Abbruch | NEIN = Fortfahren]",
|
|
"Nach Installation - Update prüfen",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Question,
|
|
MessageBoxDefaultButton.Button1 // Standard: Abbruch
|
|
);
|
|
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
MessageBox.Show("Installation wurde abgebrochen.\nBitte Änderungen vornehmen und neu installieren.",
|
|
"Abbruch", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return; // App beenden
|
|
}
|
|
|
|
// Markiere als gezeigt
|
|
Registry.CurrentUser.CreateSubKey(@"Software\KilianWirlGmbH\Verwaltung")
|
|
.SetValue("ReadMeShown", 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private static void KundenList_Laden()
|
|
{
|
|
string updatePath = @"N:\TECHNIK\Software\Wirl-Verwaltung\Listen"; //Pfad zu Listen
|
|
string dateiName = "Kundenstammblatt.csv";
|
|
string row;
|
|
string[] rows;
|
|
|
|
try
|
|
{
|
|
if (File.Exists(Path.Combine(updatePath, dateiName)))
|
|
{
|
|
string filename = Path.Combine(updatePath, dateiName);
|
|
StreamReader sr = new StreamReader(filename, Encoding.GetEncoding("iso-8859-1"));
|
|
row = string.Empty;
|
|
rows = new string[0];
|
|
int saved = 0;
|
|
int tosave = 0;
|
|
int idx = 0;
|
|
|
|
while (!sr.EndOfStream)
|
|
{
|
|
Array.Resize<string>(ref rows, ++idx);
|
|
row = sr.ReadLine();
|
|
rows[idx - 1] = row;
|
|
}
|
|
sr.Close();
|
|
|
|
|
|
foreach (string line in rows)
|
|
{
|
|
string[] linedata = line.Split(';');
|
|
if (!int.TryParse(linedata[0], out _)) continue;
|
|
if (linedata[4].Contains("Preisgruppe")) continue;
|
|
|
|
tosave++;
|
|
|
|
Kunde kunde = Kunde.GetKunde(linedata[0], null, null);
|
|
if (kunde == null) kunde = new Kunde();
|
|
|
|
kunde.KundeNummer = linedata[0];
|
|
kunde.KundeGruppe = linedata[3];
|
|
kunde.PLZ = int.TryParse(linedata[4], out int tmp2) ? tmp2 : 00;
|
|
kunde.KundeName = linedata[5];
|
|
kunde.KundeName2 = linedata[6];
|
|
kunde.Strasse = linedata[8];
|
|
kunde.Land = linedata[9];
|
|
kunde.Ort = linedata[10];
|
|
kunde.Bettenanzahl = int.TryParse(linedata[45], out int bett) ? bett : 0;
|
|
kunde.Waescheart = linedata[46];
|
|
kunde.Service = linedata[47];
|
|
kunde.Region = linedata[48];
|
|
kunde.Suchtext = linedata[55];
|
|
kunde.Aktiv = linedata[56] == "1" ? true : false;
|
|
|
|
if (kunde.Save() == 1) saved++;
|
|
}
|
|
if (saved == tosave) { Kundenliste_Importiert = true; Settings.Default.LastKundeUpdate = DateTime.Now; }
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Import fehlgeschlagen: {ex.Message}\nPfad: {updatePath}\nDatei: {dateiName}", "IMPORT FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
finally
|
|
{
|
|
if (Kundenliste_Importiert) File.Delete(Path.Combine(updatePath, dateiName));
|
|
}
|
|
}
|
|
private static bool CheckAndInstallUpdate()
|
|
{
|
|
string currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
string updatePath = @"N:\TECHNIK\Software\Wirl-Verwaltung\Setup"; // Ihr interner UNC-Pfad
|
|
|
|
try
|
|
{
|
|
string newVersion = File.ReadAllText(Path.Combine(updatePath, "Version.txt")).Trim();
|
|
|
|
if (string.IsNullOrWhiteSpace(newVersion))
|
|
{
|
|
//string msiPath = Path.Combine(updatePath, "*.msi"); // Erstes MSI finden
|
|
string[] msiFiles = Directory.GetFiles(updatePath, "SetupVerwaltung*.msi");
|
|
if (msiFiles.Length == 0) return false;
|
|
|
|
// Neueste Version aus Dateiname
|
|
string validMsis = msiFiles
|
|
.Select(f => new { Path = f, Version = GetVersionFromMsiFilename(f) })
|
|
.Where(x => IsValidVersion(x.Version))
|
|
.OrderByDescending(x => new Version(x.Version))
|
|
.FirstOrDefault()?.Version;
|
|
|
|
if (validMsis != null) newVersion = validMsis;
|
|
}
|
|
|
|
|
|
if (new Version(newVersion).CompareTo(new Version(currentVersion)) > 0)
|
|
{
|
|
DialogResult result = MessageBox.Show(
|
|
$"Update verfügbar: {newVersion}\nInstallieren?",
|
|
"UPDATE VERFÜGBAR",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Question);
|
|
|
|
string msiPath = Path.Combine(updatePath, $"SetupVerwaltung{newVersion}.msi");
|
|
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
try
|
|
{
|
|
// 1. Laufende Prozesse killen
|
|
//foreach (var proc in Process.GetProcessesByName("Deckungsbeitrag"))
|
|
// try { proc.Kill(); } catch { }
|
|
|
|
// 2. MSI lokal kopieren (umgeht UNC-Fehler 2203)
|
|
string localMsi = Path.Combine(@"C:\tmp", $"SetupVerwaltung{newVersion}.msi");
|
|
File.Copy(msiPath, localMsi, true);
|
|
|
|
// 3. MSI starten
|
|
var psi = new ProcessStartInfo
|
|
{
|
|
FileName = "msiexec.exe",
|
|
Arguments = $"/i \"{localMsi}\" /qn /norestart ALLUSERS=1 /L*v \"C:\\tmp\\update.log\"",
|
|
Verb = "runas",
|
|
UseShellExecute = true
|
|
};
|
|
|
|
// 1. SELBST schließen (wichtig!)
|
|
Application.Exit();
|
|
|
|
// 2. ALLE Prozesse killen
|
|
foreach (Process p in Process.GetProcessesByName("Deckungsbeitrag"))
|
|
if (p.Id != Process.GetCurrentProcess().Id)
|
|
p.Kill();
|
|
foreach (Process p in Process.GetProcessesByName("Wirl-Verwaltung"))
|
|
p.Kill();
|
|
|
|
foreach (Process p in Process.GetProcessesByName("SetupVerwaltung"))
|
|
p.Kill();
|
|
|
|
// 3. 2 Sekunden warten (Restart Manager)
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
Process.Start(psi)?.Dispose();
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Start fehlgeschlagen: {ex.Message}", "UPDATE FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Update-Prüfung fehlgeschlagen: {ex.Message}\nPfad: {updatePath}",
|
|
"UPDATE FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
return false;
|
|
}
|
|
private static string GetVersionFromMsiFilename(string msiFilePath)
|
|
{
|
|
string filename = Path.GetFileNameWithoutExtension(msiFilePath);
|
|
|
|
// Pattern: SetupVerwaltung1.0.44.msi → 1.0.44
|
|
// Oder: SetupVerwaltung_v1_0_44.msi → 1.0.44
|
|
Match match = Regex.Match(filename, @"(\d+(?:\.\d+){2,3})");
|
|
|
|
if (match.Success)
|
|
return match.Groups[1].Value;
|
|
|
|
return "0.0.0"; // Fallback
|
|
}
|
|
private static bool IsValidVersion(string version)
|
|
{
|
|
return Version.TryParse(version, out _);
|
|
}
|
|
private static void ImageList_Laden()
|
|
{
|
|
imagelist.Images.Add(Resources.Exclamation_Red);
|
|
imagelist.Images.Add(Resources.InformationSymbol_16x);
|
|
imagelist.Images.Add("print", Resources.PrintTag1);
|
|
imagelist.Images.Add("abschließen", Resources.checkmark);
|
|
imagelist.Images.Add("dirt", Resources.dirt);
|
|
imagelist.Images.Add("clean", Resources.clean);
|
|
imagelist.Images.Add("close", Resources.Close_red_16x);
|
|
|
|
}
|
|
|
|
}
|
|
} |