FormAutorization.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace InfoTrack
  12. {
  13. public partial class FormAutorization : Form
  14. {
  15. DataBase dataBase = new DataBase();
  16. public FormAutorization()
  17. {
  18. InitializeComponent();
  19. StartPosition = FormStartPosition.CenterScreen;
  20. }
  21. private void buttonEnter_Click(object sender, EventArgs e)
  22. {
  23. SqlDataAdapter adapter = new SqlDataAdapter();
  24. DataTable table = new DataTable();
  25. var login = textBoxForLogin.Text;
  26. var password = textBoxForPass.Text;
  27. if (login == "логин")
  28. {
  29. MessageBox.Show("Введите логин");
  30. return;
  31. }
  32. if (password == "пароль")
  33. {
  34. MessageBox.Show("Введите пароль");
  35. return;
  36. }
  37. string zapros = $"select Login from Users where Login = '{login}' and Password = '{password}'";
  38. SqlCommand command = new SqlCommand(zapros, dataBase.getConnection());
  39. adapter.SelectCommand = command;
  40. adapter.Fill(table);
  41. if (table.Rows.Count == 1)
  42. {
  43. GlobalValues.login = login;
  44. this.Hide();
  45. FormMenu form = new FormMenu();
  46. form.Show();
  47. }
  48. else
  49. {
  50. MessageBox.Show("Неверный логин или пароль");
  51. }
  52. }
  53. private void textBoxForLogin_TextChanged(object sender, EventArgs e)
  54. {
  55. if (textBoxForLogin.Text == "логин")
  56. {
  57. textBoxForLogin.Text = "";
  58. }
  59. if (textBoxForPass.Text == "")
  60. {
  61. textBoxForPass.UseSystemPasswordChar = false;
  62. textBoxForPass.Text = "пароль";
  63. }
  64. }
  65. private void textBoxForPass_TextChanged(object sender, EventArgs e)
  66. {
  67. if (textBoxForPass.Text == "пароль")
  68. {
  69. textBoxForPass.Text = "";
  70. textBoxForPass.UseSystemPasswordChar = true;
  71. }
  72. if (textBoxForLogin.Text == "")
  73. {
  74. textBoxForLogin.Text = "логин";
  75. }
  76. }
  77. private void labelForExit_Click(object sender, EventArgs e)
  78. {
  79. Application.Exit();
  80. }
  81. }
  82. }