bilet5/LoginForm.cs
2025-11-17 20:38:02 +04:00

67 lines
2.0 KiB
C#

using MySqlX.XDevAPI;
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 merkulov5
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string loginUser = loginField.Text;
string passUser = passField.Text;
if (string.IsNullOrWhiteSpace(loginField.Text))
{
MessageBox.Show("Введите логин.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(passField.Text))
{
MessageBox.Show("Введите логин.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DB db = new DB();
DataTable table = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand commandAd = new MySqlCommand("SELECT * FROM `Librarian` WHERE `Login` = @log AND `Password` = @pass", db.getConnection());
commandAd.Parameters.Add("@log", MySqlDbType.VarChar).Value = loginUser;
commandAd.Parameters.Add("@pass", MySqlDbType.VarChar).Value = passUser;
adapter.SelectCommand = commandAd;
adapter.Fill(table);
if (table.Rows.Count == 1)
{
MessageBox.Show("Авторизация успешна.");
this.Hide();
MainForm main = new MainForm();
main.Show();
}
}
}
}