Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace Grou
- {
- public partial class Frm_Login : Form
- {
- MySqlConnection conn = new MySqlConnection(Properties.Settings.Default.conexao);
- private Boolean usertype;
- public Frm_Login()
- {
- InitializeComponent();
- }
- private void Login()
- {
- if (!String.IsNullOrEmpty(TxtLogin.Text) || !String.IsNullOrEmpty(TxtSenha.Text))
- {
- conn.Open();
- try
- {
- MySqlCommand cmd = new MySqlCommand("SELECT username,password,nivel FROM grou_login WHERE username = @user AND password = @pass", conn);
- cmd.Parameters.AddWithValue("@user", TxtLogin.Text); //parametros para usuario;
- cmd.Parameters.AddWithValue("@pass", TxtSenha.Text); //parametros para senha
- MySqlDataReader mdr = cmd.ExecuteReader(); //Data Reader (Adaptador para obj cmd)
- if (mdr.Read() == true)
- {
- usertype = Convert.ToBoolean(mdr["nivel"]);
- if (usertype == true)
- {
- MessageBox.Show("ADMIN LOGADO!");
- }
- else
- {
- MessageBox.Show("NORMAL USER LOGADO");
- }
- }
- else
- {
- MessageBox.Show("Nome de usuário ou senha inválidos, Por favor tente mais tarde.");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("Ops! houve um erro desconhecido~~:", Convert.ToString(ex));
- }
- finally
- {
- conn.Close();
- }
- }
- else
- {
- MessageBox.Show("Ops! Preencha os campos corretamente!"); //se campo for vazio
- }
- }
- private void BtnLogin_Click(object sender, EventArgs e) //Btn_LOGIN
- {
- Login();
- }
- private void BtnCancel_Click(object sender, EventArgs e) //Btn_CANCEL
- {
- Application.ExitThread();
- }
- private void TxtLogin_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == 13)
- {
- Login();
- }
- }
- private void TxtSenha_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == 13)
- {
- Login();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement