0303/0303RogovaNeshina/Registration.cs
2026-03-03 15:44:38 +04:00

68 lines
3.0 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.

using MySql.Data.MySqlClient;
using System;
using System.Windows.Forms;
namespace _0303RogovaNeshina
{
public partial class Registration : Form
{
public Registration()
{
InitializeComponent();
}
string connStr = "Server=cfif31.ru;Port=3306;Database=ISPr25-21_NeshinaPV_0303;Uid=ISPr25-21_NeshinaPV;Pwd=ISPr25-21_NeshinaPV;";
private void lblBack_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
// Считываем данные из твоих полей
string firstname = tbFirstname.Text.Trim();
string lastname = tbLastname.Text.Trim();
string surname = tbSurname.Text.Trim(); // Это у тебя Отчество
string login = tbLogin.Text.Trim();
string password = tbPass.Text;
if (string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
MessageBox.Show("Заполните Фамилию, Имя, Логин и Пароль!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// ИСПРАВЛЕННЫЙ ЗАПРОС: имена столбцов теперь точно как в твоей базе (firstName, lastName, surName)
string query = "INSERT INTO librarians (firstName, lastName, surName, login, password) VALUES (@f, @l, @s, @log, @pass)";
try
{
using (MySqlConnection conn = new MySqlConnection(connStr))
{
conn.Open();
using (MySqlCommand cmd = new MySqlCommand(query, conn))
{
// Сопоставляем параметры с данными
cmd.Parameters.AddWithValue("@f", firstname); // В столбец firstName
cmd.Parameters.AddWithValue("@l", lastname); // В столбец lastName
cmd.Parameters.AddWithValue("@s", surname); // В столбец surName (Отчество)
cmd.Parameters.AddWithValue("@log", login); // В столбец login
cmd.Parameters.AddWithValue("@pass", password); // В столбец password
cmd.ExecuteNonQuery();
}
}
MessageBox.Show("Регистрация успешна! Теперь войдите.", "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Ошибка регистрации: " + ex.Message, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}