123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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 distant
- {
- public partial class Registration : Form
- {
- public Registration()
- {
- InitializeComponent();
- pictureBox2.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
- pictureBox8.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
- pictureBox4.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
- pictureBox10.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
- FormBorderStyle = FormBorderStyle.FixedSingle;
- LoginBox.Text = "Введите имя";
- LoginBox1.Text = "Введите фамилию";
- PasswordBox.Text = "Введите логин";
- PasswordBox1.Text = "Введите пароль";
- }
- private void Registration_Load(object sender, EventArgs e)
- {
- }
- private void LoginBox_Enter(object sender, EventArgs e)
- {
- if (LoginBox.Text == "Введите имя")
- LoginBox.Text = "";
- }
- private void LoginBox_Leave(object sender, EventArgs e)
- {
- if (LoginBox.Text == "")
- LoginBox.Text = "Введите имя";
- }
- private void LoginBox1_Enter_1(object sender, EventArgs e)
- {
- if (LoginBox1.Text == "Введите фамилию")
- LoginBox1.Text = "";
- }
- private void LoginBox1_Leave_1(object sender, EventArgs e)
- {
- if (LoginBox1.Text == "")
- LoginBox1.Text = "Введите фамилию";
- }
- private void PasswordBox_Enter_1(object sender, EventArgs e)
- {
- if (PasswordBox.Text == "Введите логин")
- PasswordBox.Text = "";
- }
- private void PasswordBox_Leave_1(object sender, EventArgs e)
- {
- if (PasswordBox.Text == "")
- PasswordBox.Text = "Введите логин";
- }
- private void PasswordBox1_Enter_1(object sender, EventArgs e)
- {
- if (PasswordBox1.Text == "Введите пароль")
- PasswordBox1.Text = "";
- }
- private void PasswordBox1_Leave(object sender, EventArgs e)
- {
- if (PasswordBox1.Text == "Введите пароль")
- PasswordBox1.Text = "";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (LoginBox.Text == "Введите имя")
- {
- MessageBox.Show("Введите имя");
- return;
- }
- if (PasswordBox1.Text == "Введите пароль")
- {
- MessageBox.Show("Введите пароль"); return;
- }
- if (PasswordBox.Text == "Введите логин")
- {
- MessageBox.Show("Введите пароль"); return;
- }
- if (LoginBox1.Text == "Введите фамилию")
- {
- MessageBox.Show("Введите фамилию"); return;
- }
- if (checkUser())
- return;
- Db db = new Db();
- MySqlCommand mySqlCommand = new MySqlCommand("INSERT INTO Users (login, password, name, surname) VALUES (@login, @password,@name,@surname)", db.GetConnection());
- mySqlCommand.Parameters.Add("@login", MySqlDbType.VarChar).Value = PasswordBox.Text;
- mySqlCommand.Parameters.Add("password", MySqlDbType.VarChar).Value = PasswordBox1.Text;
- mySqlCommand.Parameters.Add("@name", MySqlDbType.VarChar).Value = LoginBox.Text;
- mySqlCommand.Parameters.Add("@surname", MySqlDbType.VarChar).Value = LoginBox1.Text;
- db.openConnection();
- if (mySqlCommand.ExecuteNonQuery() == 1)
- MessageBox.Show("Аккаунт был создан");
- else
- MessageBox.Show("Аккаунт не был создан");
- db.closeConnection();
- }
- public Boolean checkUser()
- {
- Db db = new Db();
- DataTable dataTable = new DataTable();
- MySqlDataAdapter adapter = new MySqlDataAdapter();
- MySqlCommand mySqlCommand = new MySqlCommand("SELECT * FROM Users WHERE login = @login", db.GetConnection());
- mySqlCommand.Parameters.Add("@login", MySqlDbType.VarChar).Value = PasswordBox.Text;
- adapter.SelectCommand = mySqlCommand;
- adapter.Fill(dataTable);
- if (dataTable.Rows.Count > 0)
- {
- MessageBox.Show("Такой пользователь уже найден, введите другой логин");
- return true;
- }
- else
- return false;
- }
- }
- }
|