示例#1
0
 private void SubmitCommandExecute(object obj)
 {
     try
     {
         string password = (obj as PasswordBox).Password;
         if (ValidationClass.JMBGisValid(UserName) && password.Equals("Gost"))
         {
             GuestMainView guestMain = new GuestMainView(UserName);
             view.Close();
             guestMain.Show();
             return;
         }
         else if (UserName.Equals("Zaposleni") && password.Equals("Zaposleni"))
         {
             EmployeeView employeeView = new EmployeeView();
             view.Close();
             employeeView.Show();
         }
         else
         {
             MessageBox.Show("Wrong usename or password");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#2
0
        private void AddMenagerExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(MenagerToAdd.JMBG))
                {
                    MessageBox.Show("JMBG  nije validan.");
                    return;
                }

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


                if (!ValidationClass.IsValidEmail(MenagerToAdd.Email))
                {
                    MessageBox.Show("Email nije validan");
                    return;
                }

                int salary;
                if (!Int32.TryParse(Salary, out salary))
                {
                    MessageBox.Show("Plata mora biti broj");
                    return;
                }

                MenagerToAdd.RoleID      = MenagerRole.RoleID;
                MenagerToAdd.SectorID    = menagerSector.SectorID;
                MenagerToAdd.Salary      = salary;
                MenagerToAdd.DateOfBirth = StartDate;

                EmployeeList = employeeService.GetAllEmployees();

                //string textForFile = String.Format("Added user {0} {1} JMBG {2}", employee.FirstName,
                //              employee.LastName, employee.JMBG);
                //eventObject.OnActionPerformed(textForFile);
                //employee.GenderID = gender.GenderID;

                isUpdateUser = true;


                menagerService.AddMenager(MenagerToAdd);

                MenagerToAdd  = new tblEmployee();
                MenagerRole   = new tblRole();
                MenagerSector = new tblSector();
                Salary        = "";
                MessageBox.Show("Uspesno ste dodali menadzera");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void SaveExecute()
        {
            try
            {
                //tblEmployee newMenager = new tblEmployee();
                //newMenager.Username = Menager.Username;
                //newMenager.Passwd = Menager.Passwd;
                ////employeeService.AddEmployee(newMenager);

                if (!ValidationClass.IsValidEmail(Menager.Email))
                {
                    MessageBox.Show("Email is not valid");
                    return;
                }
                if (!ValidationClass.JMBGisValid(Menager.JMBG))
                {
                    MessageBox.Show("JMBG is not valid.");
                    return;
                }
                if (managerService.GetEmployeeByJMBG(Menager.JMBG) != null)
                {
                    MessageBox.Show("User with this JMBG already exists");
                    return;
                }
                if (managerService.GetEmployeeByUsername(Menager.Username) != null)
                {
                    MessageBox.Show("User with this username already exists");
                    return;
                }
                if (Menager.Salary <= 0)
                {
                    MessageBox.Show("Salary has to be grater than zero.");
                    return;
                }
                Menager.AccessLevelID = AccessLevel.ID;
                Menager.SectorID      = Sector.SectorID;
                Menager.DateOfBirth   = DateOfBirth;
                managerService.AddMenager(Menager);
                Menager = new tblEmployee();
                MessageBox.Show("You successfully added a manager.");
                LoginView loginMain = new LoginView();
                loginMain.Show();
                addMenager.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 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());
     }
 }
示例#5
0
        private void SaveExecute(object parameter)
        {
            try
            {
                DateTime dateOfBirth;

                if (!ValidationClass.JMBGisValid(User.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(User.Username);

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

                userInDb = userService.GetUserByJMBG(User.JMBG);

                if (userInDb != null)
                {
                    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);
                User.Gender        = Gender;
                User.MaritalStatus = MartialStatus;
                User.Password      = encryptedString;
                User = userService.AddUser(User);

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

                Employee.ProfessionalQualifications = Qualification;
                List <vwManager> managers = managerService.GetManagers();
                var idList = managers.Select(item => item.ManagerID).ToList();

                Random random    = new Random();
                int    index     = random.Next(idList.Count);
                int    managerId = idList[index];
                Employee.ManagerID = managerId;
                Employee.UserID    = User.UserID;

                employeeService.AddEmployee(Employee);


                //string str = string.Format("You registered as employee\nYour manager is");
                MessageBox.Show("You registered as employee");
                LoginView loginView = new LoginView();
                loginView.Show();
                view.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#6
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());
            }
        }
示例#7
0
        private void SaveExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(employee.JMBG))
                {
                    MessageBox.Show("JMBG  is not valid.");
                    return;
                }

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

                if (!ValidationClass.RegisterNumberIsValid(employee.IDNumber))
                {
                    MessageBox.Show("Registration number  is not valid. It must have 9 numbers");
                    return;
                }
                if (!ValidationClass.RegNumberIsUnique(employee.IDNumber))
                {
                    MessageBox.Show("Registration number  already exists in database");
                    return;
                }
                if (!ValidationClass.TelfonNumberValid(employee.PhoneNumber))
                {
                    MessageBox.Show("Telephone number  is not valid. It must have 9 numbers");
                    return;
                }

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


                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);

                string textForFile = String.Format("Added user {0} {1} JMBG {2}", employee.FirstName,
                                                   employee.LastName, employee.JMBG);
                eventObject.OnActionPerformed(textForFile);



                tblEmployee emplInDb = employeeService.AddEmployee(employee);

                if (sectorDB == null)
                {
                    sectorDB            = new tblSector();
                    sectorDB.SectorName = Sector;
                    sectorDB            = sectorService.AddSector(sectorDB);
                    //employee.SectorID = sectorDB.SectorID;
                    employeeService.EditSector(emplInDb.EmployeeID, sectorDB);
                }
                else
                {
                    employeeService.EditSector(emplInDb.EmployeeID, sectorDB);
                }
                employeeService.EditManager(emplInDb.EmployeeID, SelectedMenager.ID);

                addEmployee.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#8
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());
            }
        }
        private void SaveExecute(object parameter)
        {
            try
            {
                DateTime dateOfBirth;
                if (!ValidationClass.JMBGisValid(User.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\nManager has to be at least 18 years old");
                    MessageBox.Show(str1);
                    return;
                }

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

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

                userInDb = userService.GetUserByJMBG(User.JMBG);

                if (userInDb != null)
                {
                    string str1 = string.Format("User with this JMBG exists\n" +
                                                "Enter another JMBG");
                    MessageBox.Show(str1);
                    return;
                }

                if (!ValidationClass.IsValidEmail(Manager.Email))
                {
                    MessageBox.Show("Email is not valid");
                    return;
                }

                tblManager managerInDb = managerService.GetManagerByEmail(Manager.Email);

                if (managerInDb != null)
                {
                    string str1 = string.Format("Manager with this email exists\n" +
                                                "Enter another email");
                    MessageBox.Show(str1);
                    return;
                }
                var passwordBox = parameter as PasswordBox;
                var password    = passwordBox.Password;

                string encryptedString = EncryptionHelper.Encrypt(password);
                User.Gender        = Gender;
                User.MaritalStatus = MartialStatus;
                User.Password      = encryptedString;
                User = userService.AddUser(User);

                string reservePassword = string.Format("{0}WPF", Manager.ReservePassword);
                Manager.ReservePassword = reservePassword;
                Manager.UserID          = User.UserID;
                managerService.AddManager(Manager);


                string str = string.Format("You registered as manager");
                MessageBox.Show(str);
                view.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#10
0
        private void SaveExecute(object parameter)
        {
            try
            {
                DateTime dateOfBirth;

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

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

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

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

                userInDb = userService.GetUserByJMBG(User.JMBG);

                if (userInDb != null)
                {
                    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);
                User.Gender        = Gender;
                User.MaritalStatus = MartialStatus;
                User.Password      = encryptedString;
                User = userService.AddUser(User);

                DateTime today = DateTime.Now;
                Admin.ExpiryDate        = today.AddDays(7);
                Admin.AdministratorType = SelctedType;
                Admin.UserID            = User.UserID;

                adminService.AddAdmin(Admin);
                string str = string.Format("You added new admin of type {0}", SelctedType);
                MessageBox.Show(str);
                view.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#11
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());
            }
        }
        private void SaveExecute(object parameter)
        {
            try
            {
                DateTime dateOfBirth;
                if (!ValidationClass.JMBGisValid(ManagerToEdit.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\nManager has to be at least 18 years old");
                    MessageBox.Show(str1);
                    return;
                }

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

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

                userInDb = userService.GetUserByJMBG(ManagerToEdit.JMBG);

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

                if (!ValidationClass.IsValidEmail(ManagerToEdit.Email))
                {
                    MessageBox.Show("Email is not valid");
                    return;
                }

                tblManager managerInDb = managerService.GetManagerByEmail(ManagerToEdit.Email);

                if (managerInDb != null)
                {
                    if (managerInDb.Email.Equals(oldMail))
                    {
                    }
                    else
                    {
                        string str1 = string.Format("Manager with this email exists\n" +
                                                    "Enter another email");
                        MessageBox.Show(str1);
                        return;
                    }
                }
                var passwordBox = parameter as PasswordBox;
                var password    = passwordBox.Password;

                string encryptedString = EncryptionHelper.Encrypt(password);

                tblUser newUser = CreateUser(ManagerToEdit);
                newUser.Password = encryptedString;

                //string str3 = string.Format("{0} {1}", newUser.UserID,newUser.FirstName);
                //MessageBox.Show(str3);

                userService.EditUser(newUser);

                string reservePassword = string.Format("{0}WPF", Manager.ReservePassword);

                tblManager newManager = new tblManager();

                newManager.ManagerID       = ManagerToEdit.ManagerID;
                newManager.ReservePassword = reservePassword;
                newManager.Email           = ManagerToEdit.Email;
                newManager.OfficeNumber    = ManagerToEdit.OfficeNumber;


                managerService.EditManager(newManager);

                string str = string.Format("You succesfully edited you profile");
                MessageBox.Show(str);

                //ManagerMainView managerMainView = new ManagerMainView(Manager);
                //managerMainView.Show();
                view.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }