-
Notifications
You must be signed in to change notification settings - Fork 0
/
Login.cs
130 lines (106 loc) · 3.93 KB
/
Login.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
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace CS322___Projektni_zadatak___Bojana___Stajić___4596
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Hide();
Home homeForm = new Home();
homeForm.Show();
homeForm.FormClosed += (s, args) => this.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Login_Load(object sender, EventArgs e)
{
}
private void btnLogin_Click(object sender, EventArgs e)
{
}
private void Login_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void tbUsername_TextChanged(object sender, EventArgs e)
{
}
private void btnLogin_Click_1(object sender, EventArgs e)
{
try
{
string username = tbUsername.Text;
string password = tbPassword.Text;
if (string.IsNullOrWhiteSpace(username) ||
string.IsNullOrWhiteSpace(password))
{
MessageBox.Show("All fields must be filled to register!");
}
else
{
string mycon = "datasource=localhost;port=3306;username=root;password='';database=cs322_pz";
MySqlConnection con = new MySqlConnection(mycon);
con.Open();
string query = "SELECT * FROM user WHERE username = @username AND password = @password";
MySqlCommand cmd = new MySqlCommand(query, con);
cmd.Parameters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@password", password);
MySqlDataReader myReader;
myReader = cmd.ExecuteReader();
int count = 0;
string flag = string.Empty;
while (myReader.Read())
{
Shared.user_id = int.Parse(myReader["id"].ToString());
count += 1;
flag = myReader["flag"].ToString();
}
if (count == 1)
{
if (flag == "0")
{
this.Hide();
AdminPanel adminForm = new AdminPanel();
adminForm.FormClosed += (s, args) => this.Close();
adminForm.Show();
}
else if (flag == "1")
{
this.Hide();
UserPanel userForm = new UserPanel();
userForm.FormClosed += (s, args) => this.Close();
userForm.Show();
}
}
else
{
MessageBox.Show("Wrong username or password! Please Try Again.");
}
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}