FormAuthorizathion.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 FormAuthorizathion : Form
  13. {
  14. public FormAuthorizathion()
  15. {
  16. InitializeComponent();
  17. }
  18. private void cbxShowPass_CheckedChanged(object sender, EventArgs e)
  19. {
  20. tbxPass.UseSystemPasswordChar = !cbxShowPass.Checked;
  21. }
  22. public static string txtcon = @"Data Source=213.155.192.79,3002;Initial Catalog=AlfafloorGDV;Persist Security Info=True;User ID=u23golovnya;Password=br4v;Encrypt=False";
  23. string captcha = "";//правильная капча
  24. int countmiss = 0;
  25. void Getcaptcha()
  26. {
  27. tbxCaptcha.Text = "";
  28. captcha= Guid.NewGuid().ToString();
  29. captcha = captcha.Substring(0, 4).ToUpper();
  30. lblC1.Text = captcha[0].ToString();
  31. lblC2.Text = captcha[1].ToString();
  32. lblC3.Text = captcha[2].ToString();
  33. lblC4.Text = captcha[3].ToString();
  34. }
  35. private void FormAuthorizathion_Load(object sender, EventArgs e)
  36. {
  37. // TODO: This line of code loads data into the 'alfafloorGDVDataSet1.Manager' table. You can move, or remove it, as needed.
  38. this.managerTableAdapter.Fill(this.alfafloorGDVDataSet1.Manager);
  39. //this.managerTableAdapter.Update(this.alfafloorGDVDataSet1.Manager);
  40. //panelContainerCaptcha.Hide();
  41. Getcaptcha();
  42. tbxLogin.Text = "m2";
  43. tbxPass.Text = "m2";
  44. }
  45. private void btnEnter_Click(object sender, EventArgs e)
  46. {
  47. if (panelContainerCaptcha.Visible)//если капча видна
  48. {
  49. if (tbxCaptcha.Text != captcha)
  50. {
  51. MessageBox.Show("Капчи не совпадают", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  52. Getcaptcha() ;
  53. btnEnter.Enabled = false;
  54. timer4Login.Start();
  55. return;
  56. }
  57. }
  58. bsManager0.Filter = $"Login='{tbxLogin.Text}' and Password = '{tbxPass.Text}'";
  59. if (bsManager0.Count > 0 )
  60. {
  61. FormManager frm = new FormManager();
  62. this.Hide();
  63. frm.bsManager.Filter = $"Login = '{tbxLogin.Text}'";
  64. frm.ShowDialog();
  65. this.Show();
  66. Getcaptcha();
  67. tbxLogin.Clear();
  68. tbxPass.Clear();
  69. tbxLogin.Focus();
  70. panelContainerCaptcha.Visible = false;
  71. }
  72. else
  73. {
  74. MessageBox.Show("Менеджера с таким логином нет", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  75. countmiss++ ;
  76. if (panelContainerCaptcha.Visible ==false )
  77. panelContainerCaptcha.Visible = true ;
  78. return;
  79. }
  80. }
  81. private void timer4Login_Tick(object sender, EventArgs e)
  82. {
  83. btnEnter.Enabled = true ;
  84. timer4Login.Stop();
  85. }
  86. private void panelCaptcha_Paint(object sender, PaintEventArgs e)
  87. {
  88. Random rnd = new Random();
  89. for (int i = 0; i < 7; i++)
  90. {
  91. e.Graphics.DrawLine(new Pen(Color.Black, 5),79,200,-100,-200);
  92. e.Graphics.DrawLine(new Pen(Color.Black, 2), rnd.Next(panelCaptcha.Width), rnd.Next(panelCaptcha.Height), rnd.Next(panelCaptcha.Width), rnd.Next(panelCaptcha.Height));//отрисовать линию с координатами панели с капчей
  93. }
  94. }
  95. }
  96. }