Authorization.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. namespace Session_4
  11. {
  12. public partial class Authorization : Form
  13. {
  14. Timer timer1 = new Timer();
  15. int a = 0;
  16. int i = 10;
  17. public Authorization()
  18. {
  19. InitializeComponent();
  20. }
  21. private void exit_button_Click(object sender, EventArgs e)
  22. {
  23. this.Close();
  24. }
  25. void timer_Tick(object sender, EventArgs e)
  26. {
  27. timer_label.Text = String.Format("Подождите {0} секунд", --i);
  28. if (i == 0)
  29. {
  30. login_button.Enabled = true;
  31. timer_label.Text = "";
  32. (sender as Timer).Stop();
  33. a = 0;
  34. i = 10;
  35. }
  36. }
  37. private void login_button_Click(object sender, EventArgs e)
  38. {
  39. if (string.IsNullOrEmpty(login_text.Text) || string.IsNullOrEmpty(password_text.Text))
  40. {
  41. MessageBox.Show("Write login or password!");
  42. a = a + 1;
  43. if (a == 3)
  44. {
  45. timer_label.Text = String.Format("Подождите {0} секунд", i);
  46. login_button.Enabled = false;
  47. Timer timer = new Timer();
  48. timer.Interval = 1000;
  49. timer.Tick += new EventHandler(timer_Tick);
  50. timer.Start();
  51. }
  52. else
  53. {
  54. return;
  55. }
  56. }
  57. else
  58. {
  59. using(var db = new Session3_4Entities())
  60. {
  61. var user = db.Users.AsNoTracking().FirstOrDefault(u => u.Email == login_text.Text && u.Password == password_text.Text);
  62. if (user == null)
  63. {
  64. a = a + 1;
  65. MessageBox.Show("User not founded!");
  66. if (a == 3)
  67. {
  68. timer_label.Text = String.Format("Подождите {0} секунд", i);
  69. login_button.Enabled = false;
  70. Timer timer = new Timer();
  71. timer.Interval = 1000;
  72. timer.Tick += new EventHandler(timer_Tick);
  73. timer.Start();
  74. }
  75. return;
  76. }
  77. else
  78. {
  79. a = 0;
  80. if (user.RoleID == 1)
  81. {
  82. AdminForm ad = new AdminForm();
  83. login_text.Text = "";
  84. password_text.Text = "";
  85. ad.Show();
  86. Hide();
  87. }
  88. else
  89. {
  90. MessageBox.Show("Error");
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }