| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PasswordCheckDll;
- namespace СУБД_Швейная_фабрика
- {
- public partial class FormEditUser : Form
- {
- public FormEditUser()
- {
- InitializeComponent();
- }
- private void cbxPassword_CheckedChanged(object sender, EventArgs e)
- {
- tbxPas.UseSystemPasswordChar = !tbxPas.UseSystemPasswordChar;
- tbxPasRepeat.UseSystemPasswordChar = !tbxPasRepeat.UseSystemPasswordChar;
- tbxOldPas.UseSystemPasswordChar = !tbxOldPas.UseSystemPasswordChar;
- }
- private void FormEditUser_Load(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
- con.Open();
- SqlCommand cmd = new SqlCommand($@"select Fam,Name,Otch,Phone from Users where IdUser = {FormAuthorization.IdUser}",con);
- SqlDataReader res = cmd.ExecuteReader();
- res.Read();
- tbxFam.Text = res["Fam"].ToString();
- tbxName.Text = res["Name"].ToString();
- tbxOtch.Text = res["Otch"].ToString();
- tbxPhone.Text = res["Phone"].ToString();
- res.Close();
- con.Close();
- }
- private void btnSaveEdit_Click(object sender, EventArgs e)
- {
- if (tbxFam.Text == "" || tbxName.Text == "" || tbxOtch.Text == "" || tbxPhone.Text == "" || tbxPas.Text.Trim() == "")
- {
- MessageBox.Show("Поля не могут быть пустыми", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
- con.Open();
- SqlCommand cmd = new SqlCommand($@"select Fam,Name,Otch,Phone,Password from Users where IdUser = {FormAuthorization.IdUser}", con);
- SqlDataReader res = cmd.ExecuteReader();
- res.Read();
- if (res["Password"].ToString() != tbxOldPas.Text)
- {
- MessageBox.Show("Неправильно введён старый пароль", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- if (!PasswordCheckClass.PasswordCheck(tbxPas.Text))
- {
- MessageBox.Show(@"Пароли не соответствует требования: • длина пароля – минимум 6 символов;
- • обязательно и строчные и прописные символы;
- • цифр должно быть не более половины от всех символов пароля;
- • должен содержать минимум 1 символ из набора: ! @ # $ % ^.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- if (tbxPas.Text != tbxPasRepeat.Text)
- {
- MessageBox.Show("Новый пароль не совпадает", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- res.Close();
-
- SqlCommand cmdUpdate = new SqlCommand($@"update Users
- set Fam = '{tbxFam.Text}', Name = '{tbxName.Text}',Otch = '{tbxOtch.Text}',Password = '{tbxPas.Text}',Phone = '{tbxPhone.Text}'
- where IdUser = {FormAuthorization.IdUser}", con);
- cmdUpdate.ExecuteNonQuery();
- con.Close();
- MessageBox.Show("Сохранение прошло успешно", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.Close();
- }
- private void btnBack_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
|