Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1.  
  2. namespace Duken_Clickeur
  3. {
  4. public partial class LogInPage : Form
  5. {
  6. public LogInPage()
  7. {
  8. InitializeComponent();
  9. }
  10.  
  11. static string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Form1.CLocation + @"\Duken Clickeur\DukenclickerDB.mdf;Integrated Security=True";
  12. SqlConnection conn = new SqlConnection(connectionString);
  13. Form1 Game = new Form1();
  14. public static int ID;
  15. public static string PName;
  16. DBHandeler DB1 = new DBHandeler();
  17.  
  18. private void button1_Click(object sender, EventArgs e)
  19. {
  20. conn.Close();
  21. string name = @"####";
  22. conn.Open();
  23. string query = "SELECT * FROM Player WHERE Naam='" + textBox1.Text + "'";
  24. SqlCommand command = conn.CreateCommand();
  25. command.CommandText = query;
  26. SqlDataReader reader = command.ExecuteReader();
  27. if(textBox1.Text == "####")
  28. {
  29. MessageBox.Show("Invalid name");
  30. }
  31. else
  32. {
  33. try
  34. {
  35. reader.Read();
  36. name = reader.GetString(1);
  37. Console.WriteLine(name);
  38. command.Dispose();
  39. reader.Close();
  40. }
  41. catch (Exception ex)
  42. {
  43. reader.Close();
  44. }
  45. if (name == "####")
  46. {
  47. name = "";
  48. query = "INSERT INTO Player (Naam,Wachtwoord) VALUES('" + textBox1.Text + "','" + textBox2.Text + "')";
  49. Console.WriteLine(query);
  50. command.CommandText = query;
  51. command.ExecuteNonQuery();
  52. query = "SELECT Id FROM Player WHERE Naam='" + textBox1.Text + "'";
  53. command.CommandText = query;
  54. reader = command.ExecuteReader();
  55. reader.Read();
  56. ID = reader.GetInt32(0);
  57. reader.Close();
  58. DB1.SaveGame(ID, 0, 1, 1, 1, 0, 0, null, null);
  59. MessageBox.Show("Gebruiker succesvol aangemaakt.");
  60. }
  61. else
  62. {
  63. textBox1.Text = "USER ALREADY TAKEN!";
  64. }
  65. conn.Close();
  66. }
  67. }
  68.  
  69. private void BtnAanmelden_Click(object sender, EventArgs e)
  70. {
  71. conn.Open();
  72. string query = "SELECT * FROM Player WHERE Naam='" + textBox1.Text + "'";
  73. SqlCommand command = conn.CreateCommand();
  74. command.CommandText = query;
  75. SqlDataReader reader = command.ExecuteReader();
  76. try
  77. {
  78. reader.Read();
  79. string pass = reader.GetString(2);
  80. ID = reader.GetInt32(0);
  81. PName = textBox1.Text;
  82. if (pass == textBox2.Text)
  83. {
  84. MessageBox.Show("Nicesu");
  85. Game.Show();
  86. Game.UpdateGame();
  87. this.Hide();
  88. }
  89. else
  90. {
  91. MessageBox.Show("User-Password Combination not found!");
  92. }
  93. }
  94. catch
  95. {
  96. MessageBox.Show("User not found!");
  97. }
  98. conn.Close();
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement