private void SaveExecute()
 {
     try
     {
         if (!ValidationClass.IsValidEmail(Employee.Email))
         {
             MessageBox.Show("Email is not valid");
             return;
         }
         if (!ValidationClass.JMBGisValid(Employee.JMBG))
         {
             MessageBox.Show("JMBG is not valid.");
             return;
         }
         if (managerService.GetEmployeeByJMBG(Employee.JMBG) != null &&
             !Employee.JMBG.Equals(OldEmployee.JMBG))
         {
             MessageBox.Show("User with this JMBG already exists");
             return;
         }
         if (managerService.GetEmployeeByUsername(Employee.Username) != null &&
             !Employee.Username.Equals(OldEmployee.Username))
         {
             MessageBox.Show("User with this username already exists");
             return;
         }
         if (Employee.Salary <= 0)
         {
             MessageBox.Show("Salary has to be grater than zero.");
             return;
         }
         Employee.DateOfBirth = DateOfBirth;
         employeeService.EditEmployee(Employee);
         view.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#2
0
        private void SaveExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(employee.JMBG))
                {
                    MessageBox.Show("JMBG  is not valid.");
                    return;
                }



                if (!ValidationClass.RegisterNumberIsValid(employee.IDNumber))
                {
                    MessageBox.Show("Registration number  is not valid");
                    return;
                }

                if (!ValidationClass.TelfonNumberValid(employee.PhoneNumber))
                {
                    MessageBox.Show("Telefon number  is not valid. It must have 9 numbers");
                    return;
                }


                employee.DateOfBirth = StartDate;
                Employee.LocationID  = SelctedLocation.ID;

                if (SelectedMenager != null)
                {
                    employee.ManagerId = SelectedMenager.ID;
                }


                if (Gender.Equals("male"))
                {
                    employee.Gender = "M";
                }
                else if (Gender.Equals("female"))
                {
                    employee.Gender = "F";
                }
                else
                {
                    employee.Gender = "O";
                }


                tblSector sectorDB = sectorService.GetSectorByName(Sector);


                employeeService.EditEmployee(Employee);

                if (sectorDB == null)
                {
                    sectorDB            = new tblSector();
                    sectorDB.SectorName = Sector;
                    sectorDB            = sectorService.AddSector(sectorDB);

                    employeeService.EditSector(Employee.EmployeeID, sectorDB);
                }
                else
                {
                    //some comment
                    employeeService.EditSector(Employee.EmployeeID, sectorDB);
                }
                if (Employee.ManagerId != null)
                {
                    if (SelectedMenager != null)
                    {
                        employeeService.EditManager((int)Employee.EmployeeID, SelectedMenager.ID);
                    }
                    else
                    {
                        employeeService.EditManager((int)Employee.EmployeeID, 0);
                    }
                }



                string textForFile = String.Format("Updated user {0} {1} JMBG {2} to {3} {4} JMBG {5}", oldEmployee.FirstName,
                                                   oldEmployee.LastName, oldEmployee.JMBG, employee.FirstName, employee.LastName, employee.JMBG);
                eventObject.OnActionPerformed(textForFile);



                editEmployee.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#3
0
        private void SaveExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(employee.JMBG))
                {
                    MessageBox.Show("JMBG  is not valid.");
                    return;
                }

                if (!ValidationClass.JMBGIsUniqueForEditWindow(employee.JMBG, employee))
                {
                    MessageBox.Show("JMBG  already exists in database");
                    return;
                }

                if (!ValidationClass.RegisterNumberIsValid(employee.RegistrationNumber))
                {
                    MessageBox.Show("Registration number  is not valid");
                    return;
                }
                if (!ValidationClass.RegNumberIsUniqueForEdit(employee.RegistrationNumber, employee))
                {
                    MessageBox.Show("Registration number  already exists in database");
                    return;
                }
                if (!ValidationClass.TelfonNumberValid(employee.TelefonNumber))
                {
                    MessageBox.Show("Telefon number  is not valid. It must have 9 numbers");
                    return;
                }
                employee.LocationID  = SelctedLocation.LocationID;
                employee.DateOfBirth = StartDate;
                if (String.IsNullOrEmpty(selectedMenager.Menager))
                {
                    vwMenager menagerDB = employeeService.GetMenagerByName(" ");
                    employee.MenagerID = menagerDB.EmployeeID;
                }
                else
                {
                    employee.MenagerID = selectedMenager.EmployeeID;
                }

                string genderForDB;

                if (Gender.Equals("male"))
                {
                    genderForDB = "M";
                }
                else if (Gender.Equals("female"))
                {
                    genderForDB = "F";
                }
                else
                {
                    genderForDB = "O";
                }

                tblGender gender   = genderService.GetGenderByName(genderForDB);
                tblSector sectorDB = sectorService.GetSectorByName(Sector);

                if (sectorDB == null)
                {
                    sectorDB            = new tblSector();
                    sectorDB.SectorName = Sector;
                    sectorDB            = sectorService.AddSector(sectorDB);
                    employee.SectorID   = sectorDB.SectorID;
                }
                else
                {
                    employee.SectorID = sectorDB.SectorID;
                }

                employee.GenderID = gender.GenderID;

                isUpdateUser = true;

                string textForFile = String.Format("Updated user {0} {1} JMBG {2} to {3} {4} JMBG {5}", oldEmployee.FirstName,
                                                   oldEmployee.LastName, oldEmployee.JMBG, employee.FirstName, employee.LastName, employee.JMBG);
                eventObject.OnActionPerformed(textForFile);


                employeeService.EditEmployee(employee);

                editEmployee.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#4
0
        private void SaveExecute(object parameter)
        {
            try
            {
                DateTime dateOfBirth;

                if (!ValidationClass.JMBGisValid(EmployeeToEdit.JMBG, out dateOfBirth))
                {
                    MessageBox.Show("JMBG is not valid");
                    return;
                }

                int age = ValidationClass.CountAge(dateOfBirth);
                if (age < 18)
                {
                    string str1 = string.Format("JMBG is not valid\nEmployee has " +
                                                "to be at least 18 years old");
                    MessageBox.Show(str1);
                    return;
                }

                tblUser userInDb = userService.GetUserByUserName(EmployeeToEdit.Username);

                if (userInDb != null)
                {
                    if (EmployeeToEdit.Username.Equals(oldUserName))
                    {
                    }
                    else
                    {
                        string str1 = string.Format("User with this username exists\n" +
                                                    "Enter another username");
                        MessageBox.Show(str1);
                        return;
                    }
                }

                userInDb = userService.GetUserByJMBG(EmployeeToEdit.JMBG);

                if (userInDb != null)
                {
                    if (EmployeeToEdit.JMBG.Equals(oldJMBG))
                    {
                    }
                    else
                    {
                        string str1 = string.Format("User with this JMBG exists\n" +
                                                    "Enter another JMBG");
                        MessageBox.Show(str1);
                        return;
                    }
                }
                var passwordBox = parameter as PasswordBox;
                var password    = passwordBox.Password;

                string  encryptedString = EncryptionHelper.Encrypt(password);
                tblUser newUser         = CreateUser(EmployeeToEdit);


                newUser.Password = encryptedString;
                newUser          = userService.AddUser(newUser);

                EmployeeToEdit.SectorID = SelectedSector.SectorID;
                if (SelectedPosition != null)
                {
                    EmployeeToEdit.PositionID = SelectedPosition.PositionID;
                }

                EmployeeToEdit.ProfessionalQualifications = Qualification;

                tblEmployee newEmployee = CreateEmployee(EmployeeToEdit);
                newEmployee.UserID       = newUser.UserID;
                newEmployee.ManagerID    = EmployeeToEdit.ManagerID;
                newEmployee.IsNewRequest = true;

                newEmployee = employeeService.AddEmployee(newEmployee);

                tblRequestForChange newRequest = new tblRequestForChange();

                newRequest.OldEmployeeID = oldEmployee.EmployeeID;
                newRequest.NewEmployeeID = newEmployee.EmployeeID;
                newRequest.CreationDate  = DateTime.Today;

                employeeService.AddRequest(newRequest);

                //string str = string.Format("You registered as employee\nYour manager is");
                MessageBox.Show("You send request for changes to your manager");

                view.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }