221 lines
7.0 KiB
C#
221 lines
7.0 KiB
C#
using DatenDB;
|
|
using Deckungsbeitrag.AA_Forms;
|
|
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.Reflection;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using VirtualKeyboard;
|
|
|
|
namespace Deckungsbeitrag
|
|
{
|
|
public partial class FormLogin : Form
|
|
{
|
|
string progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
|
|
private QwertzKeyboard keyboard;
|
|
private OnboardingSchritt onBoardingArt;
|
|
|
|
public Benutzer Person { get; set; }
|
|
|
|
public FormLogin()
|
|
{
|
|
InitializeComponent();
|
|
this.Text += Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
}
|
|
|
|
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);
|
|
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);
|
|
}
|
|
if (keyboard != null) keyboard.Close();
|
|
}
|
|
|
|
private void ButtonAbbrechen_Click(object sender, EventArgs e)
|
|
{
|
|
if (keyboard != null) keyboard.Close();
|
|
|
|
this.DialogResult = DialogResult.Cancel;
|
|
this.Close();
|
|
}
|
|
|
|
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", "");
|
|
// if (!string.IsNullOrWhiteSpace(eingabe)) 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;
|
|
|
|
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();
|
|
|
|
if (Program.istTouch)
|
|
{
|
|
if (keyboard == null || keyboard.IsDisposed)
|
|
{
|
|
keyboard = new QwertzKeyboard(textBoxBenutzer, "isAlpha");
|
|
keyboard.Show();
|
|
}
|
|
else
|
|
{
|
|
keyboard.Close();
|
|
keyboard = new QwertzKeyboard(textBoxBenutzer, "isAlpha");
|
|
keyboard.Show();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void TextBoxPasswort_Enter(object sender, EventArgs e)
|
|
{
|
|
this.textBoxPasswort.Focus();
|
|
|
|
if (Program.istTouch)
|
|
{
|
|
if (keyboard == null || keyboard.IsDisposed)
|
|
{
|
|
keyboard = new QwertzKeyboard(textBoxPasswort, "isNumeric");
|
|
keyboard.Show();
|
|
}
|
|
else
|
|
{
|
|
keyboard.Close();
|
|
keyboard = new QwertzKeyboard(textBoxPasswort, "isNumeric");
|
|
keyboard.Show();
|
|
}
|
|
}
|
|
|
|
}
|
|
private void TextBox_Leave(object sender, EventArgs e)
|
|
{
|
|
this.buttonAnmelden.Focus();
|
|
}
|
|
|
|
private void TextBoxPwdWh_Enter(object sender, EventArgs e)
|
|
{
|
|
this.textBoxPasswort.Focus();
|
|
if (Program.istTouch)
|
|
{
|
|
if (keyboard == null || keyboard.IsDisposed)
|
|
{
|
|
keyboard = new QwertzKeyboard(textBoxPasswort, "isNumeric");
|
|
keyboard.Show();
|
|
}
|
|
else
|
|
{
|
|
keyboard.Close();
|
|
keyboard = new QwertzKeyboard(textBoxPasswort, "isNumeric");
|
|
keyboard.Show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|