コード例 #1
0
        private void SaveExecute()
        {
            try
            {
                if (EntryValidation.ValidateName(Worker.FirstName) == false)
                {
                    MessageBox.Show("First Name can only contain letters. Please try again", "Invalid input");
                    return;
                }
                if (EntryValidation.ValidateName(Worker.LastName) == false)
                {
                    MessageBox.Show("Last Name can only contain letters. Please try again", "Invalid input");
                    return;
                }
                if (EntryValidation.ValidateDate(Worker.DateOfBirth) == false)
                {
                    MessageBox.Show("Person Must be at least 16 years of age. Please try again", "Invalid input");
                    return;
                }
                if (EntryValidation.ValidatePersonalIDNumber(Worker.PersonalIDNumber) == false)
                {
                    MessageBox.Show("Personal ID nubmer you entered is not valid. Please try again", "Invalid input");
                    return;
                }
                if (EntryValidation.ValidateJmbg(Worker.JMBG) == false)
                {
                    MessageBox.Show("JMBG you entered is not valid. Please try again", "Invalid input");
                    return;
                }
                if (EntryValidation.ValidatePhone(Worker.PhoneNumber) == false)
                {
                    MessageBox.Show("Phone number you entered is not in correct format. Please try again", "Invalid input");
                    return;
                }
                Worker.GenderID = Gender.GenderID;
                Worker.SectorID = Sector.SectorID;
                if (Manager != null)
                {
                    Worker.ManagerID = Manager.WorkerID;
                }

                Worker.LocationID = Location.LocationID;
                _dbService.AddWorker(Worker);
                IsUpdateWorker = true;
                string logMessage = string.Format("Worker {0} {1} - JMBG:{2}, was added to database.", _worker.FirstName,
                                                  _worker.LastName, _worker.JMBG);
                actionEventObject.OnActionPerformed(logMessage);
                MessageBox.Show("New Worker Added Successfully!", "Info");
                _addWorker.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #2
0
 private void AddEmployeeCommandExecute(object obj)
 {
     try
     {
         if (EntryValidation.ValidateForLetters(employee.FullName) == false)
         {
             MessageBox.Show("Name can only contain letters. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateDate(employee.DateOfBirth) == false)
         {
             MessageBox.Show("Person must be at least 16 years old. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateEmail(employee.Email) == false)
         {
             MessageBox.Show("Invalid Email format. Please try again", "Invalid input");
             return;
         }
         if (employee.UserName.Length < 8)
         {
             MessageBox.Show("Username must be at least 8 characters", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateNumber(employee.FloorNumber.ToString()) == false)
         {
             MessageBox.Show("Floor must be a number", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateForLetters(employee.Citizenship) == false)
         {
             MessageBox.Show("Citizenship can only contain letters. Please try again", "Invalid input");
             return;
         }
         if (IsManagerOnGivenFloor(employee.FloorNumber) == false)
         {
             MessageBox.Show("No manager present on a given floor, please choose another floor number.", "Invalid input");
             return;
         }
         string password        = (obj as PasswordBox).Password;
         string encryptPassword = EncryptionHelper.Encrypt(password);
         employee.Password = encryptPassword;
         dataBaseService.AddEmployee(employee);
         MessageBox.Show("New employee registered successfully!", "Info");
         employeeView.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
コード例 #3
0
 private void AddManagerCommandExecute(object obj)
 {
     try
     {
         if (EntryValidation.ValidateForLetters(manager.FullName) == false)
         {
             MessageBox.Show("Name can only contain letters. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateDate(manager.DateOfBirth) == false)
         {
             MessageBox.Show("Person must be at least 16 years old. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateEmail(manager.Email) == false)
         {
             MessageBox.Show("Invalid Email format. Please try again", "Invalid input");
             return;
         }
         if (manager.UserName.Length < 8)
         {
             MessageBox.Show("Username must be at least 8 characters", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateNumber(manager.FloorNumber.ToString()) == false)
         {
             MessageBox.Show("Floor must be a number", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateNumber(manager.WorkExperience.ToString()) == false)
         {
             MessageBox.Show("Work experience must be a number", "Invalid input");
             return;
         }
         string password        = (obj as PasswordBox).Password;
         string encryptPassword = EncryptionHelper.Encrypt(password);
         manager.Password = encryptPassword;
         dataBaseService.AddManager(manager);
         MessageBox.Show("New manager registered successfully!", "Info");
         managerView.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }