Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Duken_Clickeur
- {
- public partial class LogInPage : Form
- {
- public LogInPage()
- {
- InitializeComponent();
- }
- static string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Form1.CLocation + @"\Duken Clickeur\DukenclickerDB.mdf;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connectionString);
- Form1 Game = new Form1();
- public static int ID;
- public static string PName;
- DBHandeler DB1 = new DBHandeler();
- private void button1_Click(object sender, EventArgs e)
- {
- conn.Close();
- string name = @"####";
- conn.Open();
- string query = "SELECT * FROM Player WHERE Naam='" + textBox1.Text + "'";
- SqlCommand command = conn.CreateCommand();
- command.CommandText = query;
- SqlDataReader reader = command.ExecuteReader();
- if(textBox1.Text == "####")
- {
- MessageBox.Show("Invalid name");
- }
- else
- {
- try
- {
- reader.Read();
- name = reader.GetString(1);
- Console.WriteLine(name);
- command.Dispose();
- reader.Close();
- }
- catch (Exception ex)
- {
- reader.Close();
- }
- if (name == "####")
- {
- name = "";
- query = "INSERT INTO Player (Naam,Wachtwoord) VALUES('" + textBox1.Text + "','" + textBox2.Text + "')";
- Console.WriteLine(query);
- command.CommandText = query;
- command.ExecuteNonQuery();
- query = "SELECT Id FROM Player WHERE Naam='" + textBox1.Text + "'";
- command.CommandText = query;
- reader = command.ExecuteReader();
- reader.Read();
- ID = reader.GetInt32(0);
- reader.Close();
- DB1.SaveGame(ID, 0, 1, 1, 1, 0, 0, null, null);
- MessageBox.Show("Gebruiker succesvol aangemaakt.");
- }
- else
- {
- textBox1.Text = "USER ALREADY TAKEN!";
- }
- conn.Close();
- }
- }
- private void BtnAanmelden_Click(object sender, EventArgs e)
- {
- conn.Open();
- string query = "SELECT * FROM Player WHERE Naam='" + textBox1.Text + "'";
- SqlCommand command = conn.CreateCommand();
- command.CommandText = query;
- SqlDataReader reader = command.ExecuteReader();
- try
- {
- reader.Read();
- string pass = reader.GetString(2);
- ID = reader.GetInt32(0);
- PName = textBox1.Text;
- if (pass == textBox2.Text)
- {
- MessageBox.Show("Nicesu");
- Game.Show();
- Game.UpdateGame();
- this.Hide();
- }
- else
- {
- MessageBox.Show("User-Password Combination not found!");
- }
- }
- catch
- {
- MessageBox.Show("User not found!");
- }
- conn.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement