FormReg.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using DllPass;
  12. namespace СУБД_Фабрика
  13. {
  14. public partial class FormReg : Form
  15. {
  16. public FormReg()
  17. {
  18. InitializeComponent();
  19. }
  20. private void FormReg_Load(object sender, EventArgs e)
  21. {
  22. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet.Users' table. You can move, or remove it, as needed.
  23. this.usersTableAdapter.Fill(this.sewingFactoryMURDataSet.Users);
  24. }
  25. SqlConnection Con = new SqlConnection(FormMain.txtCon);
  26. private void BtnReg_Click(object sender, EventArgs e)
  27. {
  28. if (TbxFam.Text.Trim() == "" || TbxName.Text.Trim() == "" || TbxOtch.Text.Trim() == "" || TbxLog.Text.Trim() == "" || TbxPass.Text.Trim() == "")
  29. {
  30. MessageBox.Show("Не все поля заполнены", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);
  31. return;
  32. }
  33. if(MtbxPhone.Text.Length < 16)
  34. {
  35. MessageBox.Show("Некорректный номер телефона", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);
  36. return;
  37. }
  38. if(!CheckPass.Check(TbxPass.Text))
  39. {
  40. MessageBox.Show(@"Пароль должен отвечать следующим требованиям безопасности:
  41. длина пароля – минимум 6 символов;
  42. обязательно и строчные и прописные символы;
  43. цифр должно быть не более половины от всех символов пароля;
  44. должен содержать минимум 1 символ из набора: ! @ # $ % ^.
  45. ", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);
  46. return;
  47. }
  48. BsUsers.Filter = $"Login = '{TbxLog.Text}'";
  49. if(BsUsers.Count > 0)
  50. {
  51. MessageBox.Show("Данный логин уже используется", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);
  52. return;
  53. }
  54. if(TbxPass.Text != TbxCheckPass.Text)
  55. {
  56. MessageBox.Show("Пароли не совпадают", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);
  57. return;
  58. }
  59. Con.Open();
  60. string txtQuery = $"insert into Users(Login, Pass, Role, Fam, Name, Otch, Phone) values('{TbxLog.Text}','{TbxPass.Text}',1,'{TbxFam.Text}','{TbxName.Text}','{TbxOtch.Text}','{MtbxPhone.Text}')";
  61. SqlCommand query = new SqlCommand(txtQuery, Con);
  62. query.ExecuteNonQuery();
  63. Con.Close();
  64. MessageBox.Show("Вы успешно зарегестрированы", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information);
  65. Close();
  66. }
  67. private void CbxShowPass_CheckedChanged(object sender, EventArgs e)
  68. {
  69. TbxPass.UseSystemPasswordChar = !CbxShowPass.Checked;
  70. TbxCheckPass.UseSystemPasswordChar= !CbxShowPass.Checked;
  71. }
  72. }
  73. }