Exemplo n.º 1
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());
            }
        }