/
Rejestracja.cs
123 lines (102 loc) · 3.95 KB
/
Rejestracja.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
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 System.Data.SQLite;
namespace Authentication_System
{
public partial class Rejestracja : Form
{
public Rejestracja()
{
InitializeComponent();
}
private void TextBox4_TextChanged(object sender, EventArgs e)
{
}
SprawdzW_BD auth;
private void BtnRegister_Click(object sender, EventArgs e)
{
if (txtUsername.Text != string.Empty
&& txtPassword.Text != string.Empty
&& txtConfirmPassword.Text != string.Empty
&& txtEmail.Text != string.Empty)
{
if (txtPassword.Text == txtConfirmPassword.Text)
{
checkAccount(txtUsername.Text);
}
else
{
MessageBox.Show("Hasla nie sa takie same!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void checkAccount(string username)
{
auth = new SprawdzW_BD();
auth.createDatabase();
auth.getConnection();
try {
using (SQLiteConnection con = new SQLiteConnection(auth.connectionString))
{
SQLiteCommand cmd = new SQLiteCommand();
con.Open();
int count = 0;
string query = @"SELECT * FROM Agus WHERE Username='" + username + "'";
cmd.CommandText = query;
cmd.Connection = con;
SQLiteDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
count++;
}
if (count == 1)
{
MessageBox.Show("Cos tam komunikat 33333", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else if (count == 0)
{
insertData(txtUsername.Text, txtPassword.Text, txtEmail.Text);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void insertData(string usernames, string password, string email)
{
auth = new SprawdzW_BD();
auth.getConnection();
try
{
using (SQLiteConnection con = new SQLiteConnection(auth.connectionString))
{
con.Open();
SQLiteCommand cmd = new SQLiteCommand();
string query = @"INSERT INTO Agus (Username, Password, Email) VALUES (@username, @password, @email)";
cmd.CommandText = query;
cmd.Connection = con;
cmd.Parameters.Add(new SQLiteParameter("@username", usernames));
cmd.Parameters.Add(new SQLiteParameter("@password", password));
cmd.Parameters.Add(new SQLiteParameter("@email", email));
cmd.ExecuteNonQuery();
MessageBox.Show("Dokonales rejestracji na V semestr UTP!", "Rejestracja pomyslna!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}