private void SaveExecute()
        {
            try
            {
                var db = new DataAccess();
                Employee.Surname            = Surname;
                Employee.GivenName          = GivenName;
                Employee.LocationID         = Location.LocationID;
                Employee.Sex                = Sex.ToLower();
                Employee.PersonalNo         = PersonalNo;
                Employee.DateOfBirth        = GeneratingData.GenerateBirthdate(Employee.PersonalNo);
                EmployeeAge                 = GeneratingData.CalculateAge(Employee.DateOfBirth);
                Employee.Manager            = Manager;
                Employee.Telephone          = Telephone;
                Employee.RegistrationNumber = RegistrationNumber;
                if (Sectors.Any(s => s.Name == SectorName))
                {
                    Employee.SectorID = Sectors.First(s => s.Name == SectorName).SectorID;
                }
                else
                {
                    var newSector = new tblSector()
                    {
                        Name = SectorName
                    };
                    //adding new sector to database
                    db.AddNewSector(newSector);
                    Sectors           = LoadSectors();
                    Employee.SectorID = Sectors.FirstOrDefault(s => s.Name == SectorName).SectorID;
                }

                //updating employee
                db.UpdateEmployee(Employee.EmployeeID, Employee);

                workerUpdate.RunWorkerAsync();

                IsUpdatedEmployee = true;
                updateEmployeeView.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void SaveExecute()
        {
            try
            {
                var db = new DataAccess();
                Employee.Sex = Sex.ToLower();
                Employee.RegistrationNumber = RegistrationNumber;
                Employee.PersonalNo         = PersonalNo;
                Employee.LocationID         = Location.LocationID;
                Employee.DateOfBirth        = GeneratingData.GenerateBirthdate(Employee.PersonalNo);
                if (Sectors.Any(s => s.Name == SectorName))
                {
                    Employee.SectorID = Sectors.First(s => s.Name == SectorName).SectorID;
                }
                else
                {
                    var newSector = new tblSector()
                    {
                        Name = SectorName
                    };
                    //adding new sector to database
                    db.AddNewSector(newSector);
                    Sectors           = LoadSectors();
                    Employee.SectorID = Sectors.FirstOrDefault(s => s.Name == SectorName).SectorID;
                }


                //adding new employee to database
                db.AddNewEmployee(Employee);

                workerAddNew.RunWorkerAsync();

                IsAddedNewEmployee = true;

                addNewEmployeeView.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public string this[string name]
        {
            get
            {
                CanSave = true;
                var    validate          = new Validation();
                var    db                = new DataAccess();
                string validationMessage = string.Empty;

                if (name == nameof(PersonalNo))
                {
                    if (!validate.IsValidPersonalNoFormat(PersonalNo))
                    {
                        validationMessage = "Invalid personal number format!";
                        CanSave           = false;
                    }
                    if (!validate.IsUniquePersonalNo(PersonalNo, db.LoadPersonalNumbers()))
                    {
                        validationMessage = "Personal number must be unique!";
                        CanSave           = false;
                    }
                    //if peronal number is valid we can check the age of user
                    if (validationMessage == string.Empty)
                    {
                        EmployeeAge = GeneratingData.CalculateAge(GeneratingData.GenerateBirthdate(PersonalNo));
                        if (EmployeeAge < 16)
                        {
                            validationMessage = "Persons younger than 16 years old can not be employed.";
                            CanSave           = false;
                        }
                    }
                }
                else if (name == nameof(Sex))
                {
                    if (!string.IsNullOrWhiteSpace(Sex))
                    {
                        var sexToLower = Sex.ToLower();
                        if (sexToLower != "m" && sexToLower != "f" && sexToLower != "x")
                        {
                            validationMessage = "Please use letter 'm' for male,'f' for female sex or 'x' for other!";
                            CanSave           = false;
                        }
                    }
                }
                else if (name == nameof(RegistrationNumber))
                {
                    if (RegistrationNumber.Length != 9 || !validate.IsDigitsOnly(RegistrationNumber))
                    {
                        validationMessage = "Invalid registration number format!";
                        CanSave           = false;
                    }
                    if (!validate.IsUniqueRegistrationNo(RegistrationNumber, db.LoadRegistrationNumbers()))
                    {
                        validationMessage = "Registartion number must be unique!";
                        CanSave           = false;
                    }
                }
                if (string.IsNullOrEmpty(validationMessage))
                {
                    CanSave = true;
                }

                return(validationMessage);
            }
        }