using System;
using System.Windows.Forms;
using TinyHeels.App_Code;

namespace TinyHeels
{
    public partial class ChangeCredentials : Form
    {
        public ChangeCredentials()
        {
            InitializeComponent();
        }



        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string id = (string.IsNullOrWhiteSpace(txtId.Text)) ? "" : txtId.Text;
                string idc = (string.IsNullOrWhiteSpace(txtIdConfirm.Text)) ? "" : txtIdConfirm.Text;
                if (id.Length == 0 || idc.Length == 0)
                {
                    ErrorBox er = new ErrorBox("You can not let id empty");
                    er.ShowDialog();
                }
                else
                {
                    if (id.Equals(idc))
                    {
                        Employee emp = new Employee();
                        emp.EmpId = Common.adminId;
                        emp.EmpLoginId = id;
                        emp.updateLoginId();



                        ErrorBox d = new ErrorBox("Done");
                        d.ShowDialog();
                        txtId.Text = "";
                        txtIdConfirm.Text = "";
                    }
                    else
                    {
                        ErrorBox er = new ErrorBox("Both IDs Should match");
                        er.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorBox er = new ErrorBox(ex.Message);
                er.ShowDialog();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string pwd = (string.IsNullOrWhiteSpace(txtPwd.Text)) ? "" : txtPwd.Text;
                string pwdc = (string.IsNullOrWhiteSpace(txtPwdConfirm.Text)) ? "" : txtPwdConfirm.Text;
                if (pwd.Length == 0 || pwdc.Length == 0)
                {
                    ErrorBox er = new ErrorBox("You can not let pwd empty");
                    er.ShowDialog();
                }
                else
                {
                    if (pwd.Equals(pwdc))
                    {
                        Employee emp = new Employee();
                        emp.EmpId = Common.adminId;
                        emp.EmpLoginPassword = StringCipher.Encrypt("testkey", pwd);
                        emp.updatePassword();
                        ErrorBox d = new ErrorBox("Done");
                        d.ShowDialog();
                        txtPwd.Text = "";
                        txtPwdConfirm.Text = "";

                    }
                    else
                    {
                        ErrorBox er = new ErrorBox("Both Passwords Should match");
                        er.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorBox er = new ErrorBox("Error changing login PWD");
                er.ShowDialog();
            }
        }
    }
}
