FAutoriz.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 FAutoriz : Form
  13. {
  14. public FAutoriz()
  15. {
  16. InitializeComponent();
  17. }
  18. public static string TxtCon = @"Data Source=213.155.192.79,3002;Initial Catalog=dbFabrika2024;Persist Security Info=True;User ID=u22vasiltsov;Password=etz7";
  19. string GetCapcha()
  20. {
  21. string TxtLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  22. string TxtDigit = "0123456789";
  23. string t1 = TxtLetter + TxtDigit;
  24. string capcha = "";
  25. bool FlagDigit = false;
  26. Random rnd = new Random();
  27. for (int i = 1; i <= 3; i++)
  28. {
  29. char sim = t1[rnd.Next(t1.Length)];
  30. if (char.IsDigit(sim)) FlagDigit = true;
  31. capcha += sim;
  32. }
  33. if (FlagDigit == false)
  34. capcha += TxtDigit[rnd.Next(TxtDigit.Length)];
  35. else
  36. capcha += TxtLetter[rnd.Next(TxtLetter.Length)];
  37. return capcha;
  38. }
  39. private void FAutoriz_Load(object sender, EventArgs e)
  40. {
  41. // TODO: данная строка кода позволяет загрузить данные в таблицу "dbFabrika2024DataSet.Users". При необходимости она может быть перемещена или удалена.
  42. this.usersTableAdapter.Fill(this.dbFabrika2024DataSet.Users);
  43. CmbRole.SelectedIndex = 0;
  44. LblCapcha.Text = GetCapcha();
  45. }
  46. private void Btnvhod_Click(object sender, EventArgs e)
  47. {
  48. if (TbxCapcha.Text.ToUpper() != LblCapcha.Text)
  49. {
  50. MessageBox.Show("Капча введена неверно!\nПопробуйте еще раз.");
  51. LblCapcha.Text = GetCapcha();
  52. TbxCapcha.Clear();
  53. return;
  54. }
  55. string role = CmbRole.SelectedItem.ToString();
  56. if (role == "Заказчик")
  57. role = 1.ToString();
  58. if (role == "Менеджер")
  59. role = 2.ToString();
  60. if (role == "Кладовщик")
  61. role = 3.ToString();
  62. string tbxFilter = String.Format("login = '{0}' and Passw = '{1}' and id_role = {2}", TbxLogin.Text, TbxPass.Text, role);
  63. string tbxFilterForUser = string.Format("login = '{0}'", TbxLogin.Text);
  64. usersBindingSource.Filter = tbxFilter;
  65. if (usersBindingSource.Count == 0)
  66. {
  67. MessageBox.Show(String.Format("Нет пользователя '{0}' с указанным логином и паролем!", role));
  68. return;
  69. }
  70. TbxLogin.Clear();
  71. TbxPass.Clear();
  72. this.Visible = false;
  73. if (role == "1")
  74. {
  75. FZakazchik frm = new FZakazchik();
  76. frm.id_userLabel1.Text = ((DataRowView)usersBindingSource.Current)["id_user"].ToString();
  77. frm.usersBindingSource.Filter = tbxFilterForUser;
  78. frm.ShowDialog();
  79. }
  80. if (role == "2")
  81. {
  82. FManager frm = new FManager();
  83. frm.usersBindingSource.Filter = tbxFilterForUser;
  84. frm.ShowDialog();
  85. }
  86. if (role == "3")
  87. {
  88. FKladovschik frm = new FKladovschik();
  89. frm.usersBindingSource.Filter = tbxFilterForUser;
  90. frm.ShowDialog();
  91. }
  92. this.Visible = true;
  93. this.usersTableAdapter.Fill(this.dbFabrika2024DataSet.Users);
  94. TbxLogin.Focus();
  95. TbxCapcha.Clear();
  96. LblCapcha.Text = GetCapcha();
  97. }
  98. private void LblCapcha_Paint(object sender, PaintEventArgs e)
  99. {
  100. Color[] colors = { Color.Green, Color.Black, Color.Yellow, Color.White };
  101. Random rnd = new Random();
  102. for (int i = 1; i <= rnd.Next(5, 11); i++)
  103. {
  104. int x1 = rnd.Next(LblCapcha.Width);
  105. int y1 = rnd.Next(LblCapcha.Height);
  106. int x2 = rnd.Next(LblCapcha.Width);
  107. int y2 = rnd.Next(LblCapcha.Height);
  108. Color col = colors[rnd.Next(colors.Length)];
  109. e.Graphics.DrawLine(new Pen(col), x1, y1, x2, y2);
  110. }
  111. }
  112. private void LblReg_Click(object sender, EventArgs e)
  113. {
  114. FRegistr frm1 = new FRegistr();
  115. if (frm1.ShowDialog() == DialogResult.OK)
  116. this.usersTableAdapter.Fill(this.dbFabrika2024DataSet.Users);
  117. }
  118. private void CbxShowPass_CheckedChanged(object sender, EventArgs e)
  119. {
  120. TbxPass.UseSystemPasswordChar = !TbxPass.UseSystemPasswordChar;
  121. }
  122. }
  123. }