Advertisement
Guest User

Untitled

a guest
May 19th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. int i;
  3. public LoginWindow()
  4.  
  5. {
  6. InitializeComponent();
  7. }
  8.  
  9. MySqlConnection connection = new MySqlConnection("server=localhost;userid=root;password=salasana;database=villager");
  10.  
  11.  
  12.  
  13.  
  14. private void btnLogin_Click(object sender, EventArgs e)
  15. {
  16.  
  17.  
  18. i = 0;
  19. connection.Open();
  20. MySqlCommand cmd = connection.CreateCommand();
  21. cmd.CommandType = CommandType.Text;
  22. cmd.CommandText = "select * from Login where userName='" + User.Text + "' and userPassword='" + Password.Text + "'";
  23. cmd.ExecuteNonQuery();
  24. DataTable DT = new DataTable();
  25. MySqlDataAdapter DA = new MySqlDataAdapter(cmd);
  26. DA.Fill(DT);
  27. i = Convert.ToInt32(DT.Rows.Count.ToString());
  28.  
  29.  
  30.  
  31. if (i == 0)
  32. {
  33. MessageBox.Show("invalid username or password");
  34. }
  35. else
  36. {
  37. this.Hide();
  38. new MainMenuWindow().Show();
  39. }
  40.  
  41. connection.Close();
  42. }
  43.  
  44.  
  45.  
  46. //if program is closed on login window it will ask if you want to close it
  47. protected override void OnFormClosing(FormClosingEventArgs e)
  48. {
  49.  
  50. if (LoginCancel() == false)
  51. {
  52. e.Cancel = true;
  53. };
  54. }
  55.  
  56. public static bool LoginCancel()
  57. {
  58. const string message = "Quit?";
  59. const string caption = "Exit";
  60. var result = MessageBox.Show(message, caption,
  61. MessageBoxButtons.YesNo,
  62. MessageBoxIcon.Question);
  63. // exit or stay
  64. if (result == DialogResult.Yes)
  65. return true;
  66. else
  67. return false;
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement