224 lines
6.9 KiB
C#
224 lines
6.9 KiB
C#
using DatenDB;
|
|
using Deckungsbeitrag.Properties;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Windows.Forms.LinkLabel;
|
|
|
|
namespace Deckungsbeitrag.AA_Forms
|
|
{
|
|
public partial class FormOnBoarding : Form
|
|
{
|
|
private Dictionary<string, (string text, Image bild)> OnBoardingText;
|
|
private string userid;
|
|
private OnboardingSchritt onBoardingArt;
|
|
private static string savePath = ConfigurationManager.AppSettings["DateiSavePfad"];
|
|
private string[] schritte;
|
|
private int Schritt = 0;
|
|
private int MaxSchritte;
|
|
private bool retour = false;
|
|
|
|
public FormOnBoarding()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public FormOnBoarding(string userid, OnboardingSchritt OnBoardingArt) : this()
|
|
{
|
|
// Wenn der Aufruf von Main kommt ist die userid die BenutzerRolle als string.
|
|
this.userid = userid;
|
|
this.onBoardingArt = OnBoardingArt;
|
|
}
|
|
|
|
private void FormOnBoarding_Load(object sender, EventArgs e)
|
|
{
|
|
GetDictionary();
|
|
|
|
if (OnBoardingText != null)
|
|
{
|
|
MaxSchritte = OnBoardingText.Count;
|
|
schritte = OnBoardingText.Keys.ToArray();
|
|
LoadControls(Schritt);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Buttons Vor und Zurück werden erstellt.
|
|
/// </summary>
|
|
/// <param name="schritt"></param>
|
|
private void LoadControls(int schritt)
|
|
{
|
|
if (MaxSchritte == (Schritt + 1)) { this.buttonNext.Enabled = false; this.buttonFertig.Enabled = true; }
|
|
else { this.buttonNext.Enabled = true; this.buttonFertig.Enabled = false; }
|
|
if (Schritt == 0) this.buttonPrevious.Enabled = false;
|
|
else this.buttonPrevious.Enabled = true;
|
|
|
|
if (retour)
|
|
{
|
|
this.labelHeader.Text = $"Dein OnBoarding für {onBoardingArt}";
|
|
this.pictureBoxScreen.Image = OnBoardingText[schritte[Schritt]].bild;
|
|
}
|
|
else
|
|
{
|
|
this.labelHeader.Text = $"Dein OnBoarding für {onBoardingArt}";
|
|
this.pictureBoxScreen.Image = OnBoardingText[schritte[schritt]].bild;
|
|
this.labelText.Text += OnBoardingText[schritte[schritt]].text;
|
|
}
|
|
|
|
}
|
|
private void GetDictionary()
|
|
{
|
|
switch (onBoardingArt)
|
|
{
|
|
case OnboardingSchritt.NeuerAuftrag:
|
|
switch (userid)
|
|
{
|
|
case var u when u == "fahrer":
|
|
OnBoardingText = LoadDictionary("FahrerNeuerAuftrag");
|
|
break;
|
|
case var u when u == "admin":
|
|
break;
|
|
case var u when u == "verwaltung":
|
|
break;
|
|
case var u when u == "expedit":
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
case OnboardingSchritt.Main:
|
|
// Unterscheidung zwischen UserID da Main unterschiedliche OnBoardings für User hat. (Unterschiedliche Buttons und GroupBoxen zu erklären)
|
|
switch (userid)
|
|
{
|
|
case var u when u == "fahrer":
|
|
OnBoardingText = LoadDictionary("FahrerMain");
|
|
break;
|
|
case var u when u == "admin":
|
|
break;
|
|
case var u when u == "verwaltung":
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
case OnboardingSchritt.Expedit:
|
|
break;
|
|
case OnboardingSchritt.Tourenplanung:
|
|
break;
|
|
default:
|
|
OnBoardingText = LoadDictionary("Login");
|
|
break;
|
|
}
|
|
|
|
}
|
|
private Dictionary<string, (string text, Image bild)> LoadDictionary(string art)
|
|
{
|
|
string path = Path.Combine(savePath, "OnBoarding");
|
|
string txtFile = "onboarding.txt";
|
|
Dictionary<string, (string text, Image bild)> dictionary = new Dictionary<string, (string text, Image bild)>();
|
|
|
|
if (!File.Exists(Path.Combine(path, txtFile)))
|
|
{
|
|
MessageBox.Show($"Onboarding-Datei nicht gefunden: {txtFile}", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
Program.AddFehler(null, $"Onboarding-Datei nicht gefunden: {Path.Combine(path, txtFile)}", string.Empty, null);
|
|
return null; // oder Fallback-Daten laden
|
|
}
|
|
string[] lines = File.ReadAllLines(Path.Combine(path, "onboarding.txt"));
|
|
int i = 0;
|
|
foreach (string line in lines)
|
|
{
|
|
try
|
|
{
|
|
if (!line.StartsWith(art)) continue;
|
|
var parts = line.Split('|');
|
|
string key = parts[0].Trim();
|
|
string text = parts[1].Trim();
|
|
|
|
string imagePath = Path.Combine(path, key + ".png");
|
|
if (File.Exists(imagePath))
|
|
dictionary.Add(key, (i > 0 ? Environment.NewLine + text : text, Image.FromFile(imagePath)));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Loggen oder MessageBox in WinForms
|
|
Console.WriteLine($"Fehler bei Zeile '{line}': {ex.Message}");
|
|
Program.AddFehler(null, $"Fehler bei Zeile '{line}': {ex.Message}", ex.StackTrace, null);
|
|
}
|
|
i++;
|
|
}
|
|
|
|
return dictionary;
|
|
}
|
|
|
|
private void buttonNext_Click(object sender, EventArgs e)
|
|
{
|
|
if (MaxSchritte == (Schritt + 1)) return;
|
|
this.SuspendLayout();
|
|
Schritt++;
|
|
LoadControls(Schritt);
|
|
this.ResumeLayout();
|
|
}
|
|
|
|
private void buttonPrevious_Click(object sender, EventArgs e)
|
|
{
|
|
if (Schritt == 0) return;
|
|
retour = true;
|
|
this.SuspendLayout();
|
|
Schritt--;
|
|
LoadControls(Schritt);
|
|
this.ResumeLayout();
|
|
}
|
|
|
|
private void button_EnabledChanged(object sender, EventArgs e)
|
|
{
|
|
Button btn = (Button)sender;
|
|
if (!btn.Enabled) btn.Visible = false;
|
|
else btn.Visible = true;
|
|
}
|
|
|
|
private void buttonFertig_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
|
|
private void buttonFertig_EnabledChanged(object sender, EventArgs e)
|
|
{
|
|
Button btn = (Button)sender;
|
|
if (!btn.Enabled) { btn.BackColor = Color.Gray; btn.ForeColor = Color.White; }
|
|
else { btn.BackColor = Color.Green; btn.ForeColor = Color.White; }
|
|
}
|
|
|
|
private void FormOnBoarding_Resize(object sender, EventArgs e)
|
|
{
|
|
this.labelText.MaximumSize = new Size(this.Width, 0);
|
|
this.pictureBoxScreen.Height = this.panelButtons.Top - this.labelText.Bottom;
|
|
this.pictureBoxScreen.Dock = DockStyle.Bottom;
|
|
|
|
}
|
|
|
|
private void FormOnBoarding_Shown(object sender, EventArgs e)
|
|
{
|
|
this.labelText.MaximumSize = new Size(this.Width, this.pictureBoxScreen.Top);
|
|
}
|
|
|
|
private void labelText_Resize(object sender, EventArgs e)
|
|
{
|
|
if (this.labelText.Bottom <= this.pictureBoxScreen.Top) return;
|
|
|
|
this.pictureBoxScreen.Height = this.panelButtons.Top - this.labelText.Bottom;
|
|
this.pictureBoxScreen.Dock = DockStyle.Bottom;
|
|
}
|
|
}
|
|
}
|