0303ISP41_ZvyagintsevVarfol.../Form1.cs
2026-03-05 16:46:07 +04:00

90 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ВАЖНО: Подключаем библиотеку MySQL, а не SQL Server!
using MySql.Data.MySqlClient;
using System;
using System.Windows.Forms;
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.Data.SqlClient;
using fsh;
namespace _fsh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btAutorization_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
Registration Registration = new Registration();
Registration.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
string login = textBox1.Text;
string password = textBox2.Text;
if (string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(password))
{
MessageBox.Show("Введите логин и пароль");
return;
}
string connectionString = "Server=cfif31.ru; port=3306; Database=ISPr25-21_KorotinDV_37; username=ISPr25-21_KorotinDV; password=ISPr25-21_KorotinDV; Sslmode=none";
string query = "SELECT * FROM librarians WHERE login = @login AND pass = @pass";
try
{
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
conn.Open();
using (MySqlCommand cmd = new MySqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("@login", login);
cmd.Parameters.AddWithValue("@pass", password);
object result = cmd.ExecuteScalar();
if (result != null && Convert.ToInt32(result) > 0)
{
MessageBox.Show("Успешно!", "Победа", MessageBoxButtons.OK, MessageBoxIcon.Information);
MainForm mainForm = new MainForm();
mainForm.Show();
this.Hide();
}
else
{
MessageBox.Show("Неверный логин или пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: " + ex.Message, "Критическая ошибка");
}
}
}
}