-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
176 lines (132 loc) · 4.76 KB
/
MainWindow.xaml.cs
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Collections.Generic;
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;
using MySql.Data.MySqlClient;
using System.IO;
// I am drinking maksiki right now zheer be to naxosh hahahaha
// check this:
// https://stackoverflow.com/questions/6359848/wpf-loading-spinner
namespace Lafarge_WPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
if (GlobalClass.CheckForInternetConnection())
{
// internet connection is fine
}
else
{
MessageBox.Show("Warning: you are not connected to internet!");
}
}
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
Button_Click(sender, e);
}
}
private bool login_check(String user_name, String pass)
{
MySqlCommand sql_cmd = new MySqlCommand("select username from user_account where username='" + user_name + "'", GlobalClass.con);
try
{
GlobalClass.con.Open();
GlobalClass.sql_dr = sql_cmd.ExecuteReader();
if (GlobalClass.sql_dr.HasRows)
{
GlobalClass.sql_dr.Close();
sql_cmd = new MySqlCommand("select password from user_account where username = '" + user_name + "'", GlobalClass.con);
GlobalClass.sql_dr = sql_cmd.ExecuteReader();
GlobalClass.sql_dr.Read();
if (GlobalClass.sql_dr.GetString(0) == pass)
{
//MessageBox.Show("Login successful!");
GlobalClass.Account_username = user_name;
GlobalClass.con.Close();
return true;
}
else
{
GlobalClass.con.Close();
Wrong_usrpwd.Text = "Password is incorrect for " + user_name + "!";
return false;
}
}
else
{
// if the database doesn't have the username that the user has entered.
Wrong_usrpwd.Text = "Username or Password is incorrect!";
GlobalClass.con.Close();
return false;
}
}
catch (Exception ex)
{
Wrong_usrpwd.Text = ex.Message;
MessageBox.Show("Error! Check your Internet.");
}
// this part will never be executed, just in case something wrong happens it might help.
//GlobalClass.con.Close();
return false;
}
// this event happens when you press the login button, zheer forgot to name the button lol
private void Button_Click(object sender, RoutedEventArgs e)
{
String U_Name = Username.Text;
String Pass_Word = inputPassword.Password.ToString();
Wrong_usrpwd.Text = "";
if (GlobalClass.CheckForInternetConnection())
{
GlobalClass.setCon();
GlobalClass.login_status = login_check(U_Name, Pass_Word);
if (GlobalClass.login_status)
{
//MessageBox.Show("Login successful for " + GlobalClass.Account_username);
this.Hide();
HomePage home_page = new HomePage();
home_page.ShowDialog();
}
else
{
// do nothing...
}
}
else
{
MessageBox.Show("Warning: you are not connected to internet!");
}
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Username_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Close_btn(object sender, MouseButtonEventArgs e)
{
System.Environment.Exit(1);
}
private void MiniBtn(object sender, MouseButtonEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
}
}