Esempio n. 1
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());
            }
        }
        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.RegistrationNumber))
                {
                    MessageBox.Show("Registration number  is not valid");
                    return;
                }
                if (!ValidationClass.RegNumberIsUnique(employee.RegistrationNumber))
                {
                    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;
                }

                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;


                employeeService.AddEmployee(employee);

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