aksenov_exam_main/WindowsFormsApp2/Author.cs
2026-05-14 15:56:24 +04:00

61 lines
1.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 MySql.Data.MySqlClient;
using MySqlX.XDevAPI;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace WindowsFormsApp2
{
public partial class Author : Form
{
string connectionString = "Server=85.239.57.125; Database=Gavrilov_Aksenov_exam; Uid=ISP41_Gavrilov; Pwd=ISP41_Gavrilov;";
public Author()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
conn.Open();
string query = "SELECT role FROM authorization WHERE login = @login AND pass = @pass";
using (MySqlCommand cmd = new MySqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("@login", textBox1.Text);
cmd.Parameters.AddWithValue("@pass", textBox2.Text);
object result = cmd.ExecuteScalar();
if (result != null)
{
string role = result.ToString();
if (role == "1")
{
new Admin().Show();
}
else if (role == "2")
{
new Client().Show();
}
this.Hide();
}
else
{
MessageBox.Show("Ошибка");
}
}
}
}
}
}