97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
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 System;
|
|
using System.Windows.Forms;
|
|
using MySql.Data.MySqlClient;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
using System.Data.SqlClient;
|
|
using NeshinaPolina07_11;
|
|
|
|
|
|
namespace dem
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
checkBox1.Checked = false;
|
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
textBox2.UseSystemPasswordChar = !checkBox1.Checked;
|
|
}
|
|
|
|
private void button1_Click_1(object sender, EventArgs e)
|
|
{
|
|
string login = textBox1.Text.Trim();
|
|
string password = textBox2.Text;
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
{
|
|
MessageBox.Show("Введите логин и пароль!");
|
|
return;
|
|
}
|
|
|
|
var db = DB.GetInstance();
|
|
var connection = db.GetConnection();
|
|
|
|
string query = "SELECT role_id FROM users WHERE login = @login AND password_hash = @password";
|
|
|
|
using (var command = new MySqlCommand(query, connection))
|
|
{
|
|
command.Parameters.AddWithValue("@login", login);
|
|
command.Parameters.AddWithValue("@password", password);
|
|
|
|
object result = command.ExecuteScalar();
|
|
|
|
if (result != null && int.TryParse(result.ToString(), out int roleId))
|
|
{
|
|
switch (roleId)
|
|
{
|
|
case 1:
|
|
new FORM2().Show();
|
|
break;
|
|
case 2:
|
|
new FORM3().Show();
|
|
break;
|
|
case 3:
|
|
new FORM4().Show();
|
|
break;
|
|
default:
|
|
MessageBox.Show("Неизвестная роль пользователя.");
|
|
return;
|
|
}
|
|
this.Hide();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Неверный логин или пароль! Попробуйте ещё раз.");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void groupBox1_Enter(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|