using System;
using System.Data.SqlClient;
using System.Windows.Forms;
using WindowsFormsApp3;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
// ⚙️ замени строку подключения на свою
SqlConnection con = new SqlConnection(
"Server=ZUZURIES;Database=Дэмка;Trusted_Connection=True;");
public Form1()
{
InitializeComponent();
con.Open();
new SqlCommand(
"IF OBJECT_ID('users') IS NULL " +
"CREATE TABLE users(login NVARCHAR(50), pass NVARCHAR(50))",
con).ExecuteNonQuery();
this.register.Click += new EventHandler(this.register_Click);
this.loginBtn.Click += new EventHandler(this.loginBtn_Click);
this.guestBtn.Click += new EventHandler(this.guestBtn_Click);
}
private void register_Click(object sender, EventArgs e)
{
new SqlCommand(
$"INSERT INTO users (login, password, role) VALUES('{login.Text}','{password.Text}','client')", con)
.ExecuteNonQuery();
MessageBox.Show("Пользователь добавлен!");
}
private void loginBtn_Click(object sender, EventArgs e)
{
var cmd = new SqlCommand(
$"SELECT * FROM users WHERE login='{login.Text}' AND password='{password.Text}'",
con);
var r = cmd.ExecuteReader();
if (r.Read()) { new Form2().Show(); Hide(); }
else MessageBox.Show("Неверные данные!");
r.Close();
}
private void guestBtn_Click(object sender, EventArgs e)
{
new Form2().Show(); Hide();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}