Form3.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 yrok2
  11. {
  12. public partial class Form3 : Form
  13. {
  14. Class1 database = new Class1();
  15. public Form3()
  16. {
  17. InitializeComponent();
  18. StartPosition = FormStartPosition.CenterScreen;
  19. }
  20. private void Form3_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 LoginPassword(Login, Password) values ('{login}' , '{password}')";
  28. SqlCommand command = new SqlCommand(querystring, database.GetConnection());
  29. database.openConnection();
  30. if (command.ExecuteNonQuery() == 1)
  31. {
  32. MessageBox.Show("Аккаунт успешно создан!", "Успех!");
  33. Authorization frm = new Authorization();
  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 Login, Password from LoginPassword where Login = '{loginuser}' and Password = '{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. }