using DatenDB; using Microsoft.VisualBasic; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace Deckungsbeitrag { public partial class FormLogin : Form { string progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink"; string keyboardPath; public FormLogin() { InitializeComponent(); } private void buttonAnmelden_Click(object sender, EventArgs e) { if(string.IsNullOrWhiteSpace(this.textBoxPasswort.Text)) textBoxBenutzer_Leave(sender, e); try { MD5 md5 = MD5.Create(); byte[] md5hash = md5.ComputeHash(Encoding.UTF8.GetBytes(this.textBoxPasswort.Text)); string pwdHash = string.Empty; foreach (byte b in md5hash) pwdHash += b.ToString("x2"); this.Person = Benutzer.Get(this.textBoxBenutzer.Text, pwdHash); this.Person.Save(); this.DialogResult = DialogResult.OK; this.Close(); } catch (LoginException lex) { switch (lex.ErrorCode) { case -1: MessageBox.Show(lex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Program.AddFehler(null, lex.Message, null, DateTime.Now.ToString("dd.MM.yyyy-HH-mm")); this.buttonRegistrieren.Visible = false; break; case -2: MessageBox.Show(lex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Program.AddFehler(null, lex.Message, null, DateTime.Now.ToString("dd.MM.yyyy-HH-mm")); this.buttonRegistrieren.Visible = false; break; case -3: MessageBox.Show(lex.Message, "Registrieren", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Program.AddFehler(null, lex.Message, null, DateTime.Now.ToString("dd.MM.yyyy-HH-mm")); this.buttonRegistrieren.Visible = true; this.buttonAnmelden.Enabled = false; this.groupBox1.Height = 146; this.Height = 265; this.labelPwdWh.Visible = true; this.textBoxPwdWh.Visible = true; break; case -4: MessageBox.Show(lex.Message, "Server Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Program.AddFehler(null, lex.Message, null, DateTime.Now.ToString("dd.MM.yyyy-HH-mm")); break; default: break; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } private void buttonAbbrechen_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } public Benutzer Person { get; set; } private void buttonRegistrieren_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(this.textBoxBenutzer.Text) && !String.IsNullOrEmpty(this.textBoxPasswort.Text) && this.textBoxPasswort.Text == this.textBoxPwdWh.Text) { Benutzer person = Benutzer.GetBenutzer(this.textBoxBenutzer.Text, null); //person.BenutzerName = this.textBoxBenutzer.Text; MD5 md5 = MD5.Create(); byte[] md5hash = md5.ComputeHash(Encoding.UTF8.GetBytes(this.textBoxPasswort.Text)); string pwdHash = string.Empty; foreach (byte b in md5hash) pwdHash += b.ToString("x2"); person.Passwort = pwdHash; if (person.Save() == 1) { this.groupBox1.Height = 100; this.Height = 222; this.labelPwdWh.Visible = false; this.textBoxPwdWh.Visible = false; this.buttonRegistrieren.Visible = false; this.textBoxPasswort.Text = this.textBoxPwdWh.Text = string.Empty; if (MessageBox.Show($"Benutzer {this.textBoxBenutzer.Text} wurde erfolgreich angelegt.\n\nMöchtest du einen eigenen Benutzername angeben?\n\n[JA] -> Neuen Benutzername anlegen\n[NEIN] -> Alten Benutzername behalten", "Hinweis", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { string eingabe = Interaction.InputBox("Welchen Benutzername möchtest du verwenden?\n\nBenutzername:", "Neuer Benutzername", ""); person.BenutzerName = eingabe; if (person.Save() != 1) MessageBox.Show("Benutzername konnte nicht gespeichert werden. Melde dich bei deinem Vorgesetzten.", "SPEICHERFEHLER", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.textBoxBenutzer.Focus(); this.buttonAnmelden.Enabled = true; } } } private void textBoxBenutzer_Leave(object sender, EventArgs e) { if (textBoxBenutzer.Text.Contains(";")) { this.textBoxPasswort.Text = this.textBoxBenutzer.Text.Substring(this.textBoxBenutzer.Text.IndexOf(";") + 1); this.textBoxBenutzer.Text = this.textBoxBenutzer.Text.Substring(0, this.textBoxBenutzer.Text.IndexOf(";")); } } private void FormLogin_Load(object sender, EventArgs e) { this.groupBox1.Height = 110; this.labelPwdWh.Visible = false; this.textBoxPwdWh.Visible = false; this.buttonRegistrieren.Visible = false; this.textBoxBenutzer.Focus(); WindowState = FormWindowState.Normal; StartPosition = FormStartPosition.CenterScreen; } private void FormLogin_Shown(object sender, EventArgs e) { StartPosition = FormStartPosition.CenterScreen; } private void textBoxBenutzer_Enter(object sender, EventArgs e) { this.textBoxBenutzer.SelectAll(); //// Pfad zur Touch-Tastatur //keyboardPath = System.IO.Path.Combine(progFiles, "TabTip.exe"); //// Bildschirmtastatur starten //Process.Start(keyboardPath); } private void textBoxPasswort_Enter(object sender, EventArgs e) { //// Pfad zur Touch-Tastatur //keyboardPath = System.IO.Path.Combine(progFiles, "TabTip.exe"); //// Bildschirmtastatur starten //Process.Start(keyboardPath); } private void textBox_Leave(object sender, EventArgs e) { } } }