Registration.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. namespace Khozeev8
  11. {
  12. public partial class Registration : Form
  13. {
  14. Database database = new Database();
  15. public Registration()
  16. {
  17. InitializeComponent();
  18. StartPosition = FormStartPosition.CenterScreen;
  19. }
  20. private void Registration_Load(object sender, EventArgs e)
  21. {
  22. }
  23. private void button1_Click(object sender, EventArgs e)
  24. {
  25. var login = textBox1.Text;
  26. var password = textBox2.Text;
  27. string querystring = $"insert into Пользователи(Логин, Пароль) values ('{login}' , '{password}')";
  28. SqlCommand command = new SqlCommand(querystring, database.GetConnection());
  29. database.openConnection();
  30. if (command.ExecuteNonQuery() == 1)
  31. {
  32. MessageBox.Show("Аккаунт успешно создан!", "Успех!");
  33. Aithorization frm = new Aithorization();
  34. this.Hide();
  35. frm.Show();
  36. }
  37. else
  38. {
  39. MessageBox.Show("Аккаунт не создан!");
  40. }
  41. database.closeConnection();
  42. }
  43. private Boolean checkuser()
  44. {
  45. var loginuser = textBox1.Text;
  46. var passuser = textBox2.Text;
  47. SqlDataAdapter adapter = new SqlDataAdapter();
  48. DataTable table = new DataTable();
  49. string querystring = $"select Логин, Пароль from Пользователи where Логин = '{loginuser}' and Пароль = '{passuser}'";
  50. SqlCommand command = new SqlCommand(querystring, database.GetConnection());
  51. adapter.SelectCommand = command;
  52. adapter.Fill(table);
  53. if (table.Rows.Count > 0)
  54. {
  55. MessageBox.Show("Пользователь уже существует!");
  56. return true;
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62. }
  63. }
  64. }