165 lines
5.3 KiB
C#
165 lines
5.3 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 = this.textBoxPwdWh.Bottom + 20;
|
|
this.Height = 300;
|
|
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;
|
|
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)
|
|
{
|
|
this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2, ((Screen.PrimaryScreen.WorkingArea.Height / 2) - this.Height) / 2);
|
|
}
|
|
private void TextBox_Leave(object sender, EventArgs e)
|
|
{
|
|
//this.buttonAnmelden.Focus();
|
|
}
|
|
|
|
private void TextBoxes_Enter(object sender, EventArgs e)
|
|
{
|
|
TextBox tb = (TextBox)sender;
|
|
keyboard = Funktionen.OpenVirtualKeyboard(sender);
|
|
|
|
this.BeginInvoke(new Action(() =>
|
|
{
|
|
if (!tb.IsDisposed && tb.CanFocus)
|
|
{
|
|
tb.Focus();
|
|
tb.SelectAll();
|
|
}
|
|
}));
|
|
|
|
}
|
|
}
|
|
}
|