Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace MaraphonSkills2
  13. {
  14.     public partial class Authentification : Form
  15.     {
  16.         public Authentification()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void button7_Click(object sender, EventArgs e)
  22.         {
  23.             Form1 mainscreen = new Form1();
  24.             mainscreen.Show();
  25.             this.Hide();
  26.         }
  27.  
  28.         private void button2_Click(object sender, EventArgs e)
  29.         {
  30.             Form1 mainscreen = new Form1();
  31.             mainscreen.Show();
  32.             this.Hide();
  33.         }
  34.  
  35.         private void button1_Click(object sender, EventArgs e)
  36.         {
  37.             String login, password, role;  
  38.             String connectionString = "server=localhost;" +
  39.                                       "database=wstest;" +
  40.                                       "user=root;" +
  41.                                       "password=524656bnm";
  42.             String commandString = "select Email, Password, RoleId from user where Email=@email and Password=@pass;";
  43.             MySqlConnection connection = new MySqlConnection(connectionString);
  44.             MySqlCommand command = new MySqlCommand(commandString, connection);
  45.             command.CommandText = commandString;
  46.             DataTable dt = new DataTable();
  47.             connection.Open();
  48.             //adding parameters
  49.             command.Parameters.Add("@email", MySqlDbType.VarChar, 100).Value = textBox1.Text;
  50.             command.Parameters.Add("@pass", MySqlDbType.VarChar, 100).Value = textBox2.Text;
  51.            
  52.             command.ExecuteNonQuery();
  53.             MySqlDataAdapter adapter = new MySqlDataAdapter(command);
  54.             adapter.Fill(dt);
  55.             dataGridView1.DataSource = dt;
  56.             login = dt.Rows[0][0].ToString();
  57.             password = dt.Rows[0][1].ToString();
  58.             role = dt.Rows[0][2].ToString();
  59.             MessageBox.Show(role);
  60.  
  61.             if (login == textBox1.Text && password == textBox2.Text)
  62.             {
  63.                 //MessageBox.Show("Correct");
  64.                 //adminform af = new adminform();
  65.                 //af.Show();
  66.                 //this.Hide();
  67.             }
  68.  
  69.             /*
  70.             MySqlDataReader reader = command.ExecuteReader();
  71.            
  72.             try
  73.             {
  74.                 MessageBox.Show(reader.GetString(0) + " " + reader.GetString(1));
  75.                 if (reader["Email"].ToString() == textBox1.Text && reader["Password"].ToString() == textBox2.Text)
  76.                 {
  77.                    
  78.                     adminform af = new adminform();
  79.                     af.Show();
  80.                     this.Hide();
  81.  
  82.                 }
  83.             }
  84.             catch (MySqlException ex)
  85.             {
  86.                 Console.WriteLine("Error: \r\n{0}", ex.ToString());
  87.             }
  88.             finally
  89.             {
  90.                 command.Connection.Close();
  91.             }*/
  92.             connection.Close();
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement