Form1.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Cafe12
  12. {
  13. public partial class AutorizationForm : Form
  14. {
  15. ClassCON classCON = new ClassCON();
  16. public AutorizationForm()
  17. {
  18. InitializeComponent();
  19. StartPosition = FormStartPosition.CenterScreen;
  20. }
  21. private void label1_Click(object sender, EventArgs e)
  22. {
  23. }
  24. private void label2_Click(object sender, EventArgs e)
  25. {
  26. }
  27. private void button1_Click(object sender, EventArgs e)
  28. {
  29. var loginUser = textBox2.Text;
  30. var passUser = textBox1.Text;
  31. SqlConnection conn = new SqlConnection("Data Source=class31000;Initial Catalog=CHER_KAFE;Integrated Security=True");
  32. conn.Open();
  33. SqlDataAdapter adapter = new SqlDataAdapter();
  34. DataTable table = new DataTable();
  35. SqlCommand cmd = new SqlCommand("SELECT ID_Роли FROM Пользователи WHERE Логин=@username AND Пароль=@password", conn);
  36. cmd.Parameters.AddWithValue("@username", loginUser);
  37. cmd.Parameters.AddWithValue("@password", passUser);
  38. SqlDataReader reader = cmd.ExecuteReader();
  39. if (reader.HasRows)
  40. {
  41. reader.Read();
  42. int role = reader.GetInt32(0);
  43. if (role == 1)
  44. {
  45. AdministrationForm administrator = new AdministrationForm();
  46. administrator.ShowDialog();
  47. }
  48. else if (role == 2)
  49. {
  50. OficiantForm meneger = new OficiantForm();
  51. meneger.Show();
  52. }
  53. else if (role == 3)
  54. {
  55. PovarMenu torgash = new PovarMenu();
  56. torgash.Show();
  57. }
  58. }
  59. else
  60. {
  61. MessageBox.Show("не авторизован");
  62. }
  63. conn.Close();
  64. }
  65. private void textBox1_TextChanged(object sender, EventArgs e)
  66. {
  67. textBox1.PasswordChar = '*';
  68. textBox1.MaxLength = 50;
  69. textBox1.MaxLength = 50;
  70. }
  71. private void textBox2_TextChanged(object sender, EventArgs e)
  72. {
  73. }
  74. }
  75. }