using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DLLPass;

namespace СУБД_Швейная_фабрика
{
    public partial class FormProfil : Form
    {
        public FormProfil()
        {
            InitializeComponent();
        }

        private void FormProfil_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'fabricDeryugoDataSet.Users' table. You can move, or remove it, as needed.
            this.usersTableAdapter.Fill(this.fabricDeryugoDataSet.Users);

        }

        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (TbxOldPass.Text != LblPass.Text)
            {
                MessageBox.Show("Вы ввели неверный текущий пароль!", "Внимание",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (TbxNewPass.Text != "")  // изменяется пароль
            {
                if (!ClassCheckPass.CheckPass(TbxNewPass.Text))
                {
                    MessageBox.Show("Новый пароль не соответствует требованиям!",
                        "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                // поместить в БД новый пароль
                LblPass.Text = TbxNewPass.Text;
            }

            usersBindingSource.EndEdit();
            this.usersTableAdapter.Update(this.fabricDeryugoDataSet.Users);

            this.DialogResult = DialogResult.OK;
            Close();
        }

        private void CbxShowPass_CheckedChanged(object sender, EventArgs e)
        {
            TbxNewPass.UseSystemPasswordChar = !TbxNewPass.UseSystemPasswordChar;
            TbxOldPass.UseSystemPasswordChar = !TbxOldPass.UseSystemPasswordChar;
        }

        private void usersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.usersBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.fabricDeryugoDataSet);

        }
    }
}
