Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int i;
- public LoginWindow()
- {
- InitializeComponent();
- }
- MySqlConnection connection = new MySqlConnection("server=localhost;userid=root;password=salasana;database=villager");
- private void btnLogin_Click(object sender, EventArgs e)
- {
- i = 0;
- connection.Open();
- MySqlCommand cmd = connection.CreateCommand();
- cmd.CommandType = CommandType.Text;
- cmd.CommandText = "select * from Login where userName='" + User.Text + "' and userPassword='" + Password.Text + "'";
- cmd.ExecuteNonQuery();
- DataTable DT = new DataTable();
- MySqlDataAdapter DA = new MySqlDataAdapter(cmd);
- DA.Fill(DT);
- i = Convert.ToInt32(DT.Rows.Count.ToString());
- if (i == 0)
- {
- MessageBox.Show("invalid username or password");
- }
- else
- {
- this.Hide();
- new MainMenuWindow().Show();
- }
- connection.Close();
- }
- //if program is closed on login window it will ask if you want to close it
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- if (LoginCancel() == false)
- {
- e.Cancel = true;
- };
- }
- public static bool LoginCancel()
- {
- const string message = "Quit?";
- const string caption = "Exit";
- var result = MessageBox.Show(message, caption,
- MessageBoxButtons.YesNo,
- MessageBoxIcon.Question);
- // exit or stay
- if (result == DialogResult.Yes)
- return true;
- else
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement