Form1.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace testkonkurs1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void sing_in_Click(object sender, EventArgs e)
  20. {
  21. string connString = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=Testkonkurs;Integrated Security=True";
  22. SqlConnection conn = new SqlConnection(connString);
  23. SqlCommand command = new SqlCommand("SELECT * FROM users WHERE login = @login AND password = @password", conn);
  24. command.Parameters.AddWithValue("@login", login.Text);
  25. command.Parameters.AddWithValue("@password", password.Text);
  26. conn.Open();
  27. SqlDataReader Reader = null;
  28. try
  29. {
  30. Reader = command.ExecuteReader();
  31. if (Reader.HasRows)
  32. {
  33. Reader.Read();
  34. int rols = 0;
  35. if((Reader["admin"].ToString()) == "1" &&(adminCheck.Checked))
  36. {
  37. Form2 fr2 = new Form2();
  38. fr2.Show();
  39. this.Hide();
  40. rols = 1;
  41. }
  42. if ((Reader["manager"].ToString() == "1")&& (managerCheck.Checked))
  43. {
  44. Form3 fr3 = new Form3();
  45. fr3.Show();
  46. this.Hide();
  47. rols = 1;
  48. }
  49. if (rols == 0)
  50. {
  51. MessageBox.Show("Выбрана неправильная роль", "ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Information);
  52. }
  53. }
  54. else
  55. {
  56. MessageBox.Show("Неправильно введен логин или пароль", "ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Information);
  57. }
  58. }
  59. catch(Exception ex)
  60. {
  61. MessageBox.Show(ex.Message.ToString(),"", MessageBoxButtons.OK, MessageBoxIcon.Error);
  62. }
  63. }
  64. private void password_TextChanged(object sender, EventArgs e)
  65. {
  66. }
  67. private void login_Enter(object sender, EventArgs e)
  68. {
  69. if(login.Text == "Введите логин")
  70. {
  71. login.Text = "";
  72. }
  73. }
  74. private void login_Leave(object sender, EventArgs e)
  75. {
  76. if (login.Text == "")
  77. {
  78. login.Text = "Введите логин";
  79. }
  80. }
  81. private void password_Enter(object sender, EventArgs e)
  82. {
  83. if (password.Text == "Введите пароль")
  84. {
  85. password.Text = "";
  86. }
  87. }
  88. private void password_Leave(object sender, EventArgs e)
  89. {
  90. if (password.Text == "")
  91. {
  92. password.Text = "Введите пароль";
  93. }
  94. }
  95. }
  96. }