FormAuthorization.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. using System.Data.Entity;
  11. namespace KadroviYshot
  12. {
  13. public partial class FormAuthorization : Form
  14. {
  15. DataBase database = new DataBase();
  16. public FormAuthorization()
  17. {
  18. InitializeComponent();
  19. StartPosition = FormStartPosition.CenterScreen;
  20. }
  21. private void btnEnter_Click(object sender, EventArgs e)
  22. {
  23. var loginUser = textBoxLogin.Text;
  24. var passUser = textBoxPassword.Text;
  25. SqlDataAdapter adapter = new SqlDataAdapter();
  26. DataTable table = new DataTable();
  27. string querystring = $"select IdUser, Login, Password from Users where Login='{loginUser}' and Password='{passUser}'";
  28. SqlCommand command = new SqlCommand(querystring, database.getConnection());
  29. adapter.SelectCommand = command;
  30. adapter.Fill(table);
  31. if (table.Rows.Count == 1)
  32. {
  33. MessageBox.Show("Вы успешно вошли!", "Успешно!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  34. FormAuthorization authorization = new FormAuthorization();
  35. this.Hide();
  36. authorization.ShowDialog();
  37. this.Show();
  38. }
  39. else
  40. MessageBox.Show("Такого аккаунта не существует!", "Аккаунта не существует!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  41. }
  42. private void FormAuthorization_Load(object sender, EventArgs e)
  43. {
  44. textBoxLogin.MaxLength = 50;
  45. textBoxPassword.MaxLength = 50;
  46. }
  47. }
  48. }