FormAutorization.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 СУБД_Альфапол
  11. {
  12. public partial class FormAutorization : Form
  13. {
  14. public FormAutorization()
  15. {
  16. InitializeComponent();
  17. }
  18. public static string txtCon = "Data Source=213.155.192.79,3002;Initial Catalog=dbAlphapolAG;Persist Security Info=True;User ID=u22grozdev;Password=ft9k;Encrypt=False;TrustServerCertificate=True";
  19. string Captcha;
  20. void GetCaptcha()
  21. {
  22. Captcha = Guid.NewGuid().ToString();
  23. Captcha = Captcha.Substring(0, 4).ToUpper();
  24. LblC1.Text = Captcha[0].ToString();
  25. LblC2.Text = Captcha[1].ToString();
  26. LblC3.Text = Captcha[2].ToString();
  27. LblC4.Text = Captcha[3].ToString();
  28. TbxCaptcha.Clear();
  29. }
  30. private void Form1_Load(object sender, EventArgs e)
  31. {
  32. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.Manager' table. You can move, or remove it, as needed.
  33. this.managerTableAdapter.Fill(this.dbAlphapolAGDataSet.Manager);
  34. }
  35. private void cbxShowPass_CheckedChanged(object sender, EventArgs e)
  36. {
  37. tbxPass.UseSystemPasswordChar = !cbxShowPass.Checked;
  38. }
  39. private void btnLogin_Click(object sender, EventArgs e)
  40. {
  41. BsUsers.Filter = $"Login = '{tbxLogin.Text}' and Password = '{tbxPass.Text}'";
  42. if (PanelInputCaptcha.Visible)
  43. {
  44. if (TbxCaptcha.Text != Captcha)
  45. {
  46. GetCaptcha();
  47. btnLogin.Enabled = false;
  48. timerForLogin.Start();
  49. MessageBox.Show("Символы капчи введены неверно!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  50. return;
  51. }
  52. }
  53. if (BsUsers.Count == 0)
  54. {
  55. if (PanelInputCaptcha.Visible == false)
  56. {
  57. GetCaptcha();
  58. PanelInputCaptcha.Visible = true;
  59. }
  60. else
  61. {
  62. btnLogin.Enabled = false;
  63. timerForLogin.Start();
  64. }
  65. MessageBox.Show("Нет пользователя с указанным логином и паролем", "Внимание", MessageBoxButtons.OK,
  66. MessageBoxIcon.Information);
  67. return;
  68. }
  69. this.Hide();
  70. FormManager frmManager = new FormManager();
  71. frmManager.bsUsers.Filter = BsUsers.Filter;
  72. frmManager.ShowDialog();
  73. this.Show();
  74. tbxLogin.Clear();
  75. tbxPass.Clear();
  76. tbxLogin.Focus();
  77. PanelInputCaptcha.Visible = false;
  78. this.managerTableAdapter.Fill(this.dbAlphapolAGDataSet.Manager);
  79. }
  80. private void timerForLogin_Tick(object sender, EventArgs e)
  81. {
  82. timerForLogin.Stop();
  83. btnLogin.Enabled = true;
  84. }
  85. private void panel1_Paint(object sender, PaintEventArgs e)
  86. {
  87. }
  88. private void tbxPass_TextChanged(object sender, EventArgs e)
  89. {
  90. }
  91. }
  92. }