78 lines
2.9 KiB
C#
78 lines
2.9 KiB
C#
using _fsh;
|
||
using MySql.Data.MySqlClient;
|
||
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;
|
||
|
||
namespace fsh
|
||
{
|
||
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; SslMode=none;";
|
||
|
||
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 = textBox1.Text.Trim();
|
||
string lastname = textBox2.Text.Trim();
|
||
string surname = textBox3.Text.Trim();
|
||
string login = textBox4.Text.Trim();
|
||
string password = textBox5.Text;
|
||
|
||
if (string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
||
{
|
||
MessageBox.Show("Заполните Фамилию, Имя, Логин и Пароль!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|