Form1.cs 2.8 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 KazarinDE
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void textBox2_TextChanged(object sender, EventArgs e)
  20. {
  21. }
  22. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  23. {
  24. if (checkBox1.Checked)
  25. {
  26. textBox2.PasswordChar = '\0';
  27. }
  28. else
  29. {
  30. textBox2.PasswordChar = '●';
  31. }
  32. }
  33. private void pictureBox1_Click(object sender, EventArgs e)
  34. {
  35. }
  36. private void textBox1_TextChanged(object sender, EventArgs e)
  37. {
  38. }
  39. private void label2_Click(object sender, EventArgs e)
  40. {
  41. }
  42. private void label1_Click(object sender, EventArgs e)
  43. {
  44. }
  45. private void button1_Click(object sender, EventArgs e)
  46. {
  47. string username = textBox1.Text;
  48. string password = textBox2.Text;
  49. SqlConnection conn = new SqlConnection(@"Data Source=Class31000;Initial Catalog=KazarinDE_03;Integrated Security=True");
  50. conn.Open();
  51. SqlCommand cmd = new SqlCommand("SELECT Роли, Статус FROM Сотрудники WHERE Username=@username AND Password=@password", conn);
  52. cmd.Parameters.AddWithValue("@username", username);
  53. cmd.Parameters.AddWithValue("@password", password);
  54. SqlDataReader reader = cmd.ExecuteReader();
  55. if (reader.HasRows)
  56. {
  57. reader.Read();
  58. int Roles = reader.GetInt32(0);
  59. int status = reader.GetInt32(1);
  60. if (status == 1)
  61. {
  62. if (Roles == 1)
  63. {
  64. Form2 administrator = new Form2();
  65. administrator.Show();
  66. this.Hide();
  67. }
  68. else if (Roles == 2)
  69. {
  70. Form3 waiters = new Form3();
  71. waiters.Show();
  72. this.Hide();
  73. }
  74. else if (Roles == 3)
  75. {
  76. Form4 cooks = new Form4();
  77. cooks.Show();
  78. this.Hide();
  79. }
  80. }
  81. else
  82. {
  83. MessageBox.Show("Отказано в доступе");
  84. }
  85. }
  86. }
  87. }
  88. }