-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
112 lines (100 loc) · 3.54 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
112 lines (100 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BOP3_Task_1_C_Sharp_Application_Development
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public string errorLabel;
public MainWindow()
{
InitializeComponent();
determineLanguage();
}
static public int FindUser(string userName, string password)
{
MySqlConnection c = new MySqlConnection(SharedDataHelp.conString);
c.Open();
MySqlCommand cmd = new MySqlCommand($"SELECT userId FROM user WHERE userName = '{userName}' AND password = '{password}'", c);
MySqlDataReader rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
rdr.Read();
SharedDataHelp.setCurrentUserId(Convert.ToInt32(rdr[0]));
SharedDataHelp.setCurrentUserName(userName);
rdr.Close(); c.Close();
return SharedDataHelp.getCurrentUserId();
}
return 0;
}
private void login_Click(object sender, EventArgs e)
{
if (FindUser(usernameTextBox.Text, passwordTextBox.Password) != 0)
{
this.Hide();
Dashboard dashboard = new Dashboard();
dashboard.loginForm = this;
// Logger.writeUserLoginLog(DataHelper.getCurrentUserId());
dashboard.Show();
}
else
{
MessageBox.Show(errorLabel);
passwordTextBox.Clear();
}
}
private void determineLanguage()
{
switch (RegionInfo.CurrentRegion.EnglishName)
{
case "Germany":
GermanLoginForm();
break;
case "United States":
EnglishLoginForm();
break;
default:
EnglishLoginForm();
break;
}
}
private void EnglishLoginForm()
{
LoginHeading.Text = "Log In";
usernameTextBlock.Text = "Username";
passwordTextBlock.Text = "Password";
errorLabel = "The username and password did not match";
loginButton.Content = "Login";
projectNameTextBlock.Text = "Software Development Capstone(RYM2) - Task 2";
classNameTextBlock.Text = "Software Development Capstone C868";
studentNameTextBlock.Text = "By: Luke Melton";
}
private void GermanLoginForm()
{
LoginHeading.Text = "Einloggen";
usernameTextBlock.Text = "Nutzername";
passwordTextBlock.Text = "Passwort";
errorLabel = "Der Benutzername und das Passwort stimmten nicht überein";
loginButton.Content = "Einloggen";
projectNameTextBlock.Text = "BOP3-Aufgabe 1: C#-Anwendungsentwicklung";
classNameTextBlock.Text = "Software II – Erweitertes C# – C969";
studentNameTextBlock.Text = "Von: Luke Melton";
}
}
}