Esempio n. 1
0
        public EditEmployeeViewModel(EditEmployee editEmployeeOpen, vwEmployee employeeEdit)
        {
            eventObject     = new EventClass();
            editEmployee    = editEmployeeOpen;
            selectedMenager = new vwMenager();
            employee        = employeeEdit;

            selctedLocation = new vwLOCATION();
            selectedMenager = new vwMenager();
            //selectedMenager.Menager = employee.MenagerName;
            StartDate = (DateTime)employee.DateOfBirth;
            Sector    = employee.SectorName;

            locationService = new LocationService();
            employeeService = new EmployeeService();
            genderService   = new GenderService();
            sectorService   = new SectorService();

            LocationList = locationService.GetAllLocations().ToList();
            LocationList.OrderByDescending(x => x.Location);
            LocationList.Reverse();

            PotentialMenagers = employeeService.GetAllPotentialMenagersForEditWindow(employeeEdit.EmployeeID);

            eventObject.ActionPerformed += ActionPerformed;

            oldEmployee           = new vwEmployee();
            oldEmployee.FirstName = employee.FirstName;
            oldEmployee.LastName  = employee.LastName;
            oldEmployee.JMBG      = employee.JMBG;
        }
        public MainWindowViewModel(MainWindow mainOpen)
        {
            main = mainOpen;

            locationService = new LocationService();
            employeeService = new EmployeeService();

            if (locationService.GetAllLocations().Count == 0)
            {
                LocationFileActions.AddLocationsToDatabase();
            }

            vwMenager firstMenager = employeeService.GetMenagerByName(" ");

            if (firstMenager == null)
            {
                employeeService.AddEmptyMenager();
            }

            Employees = employeeService.GetAllEmployees();

            worker         = new BackgroundWorker();
            worker.DoWork += DoWork;
            worker.WorkerReportsProgress      = true;
            worker.WorkerSupportsCancellation = true;
            worker.RunWorkerCompleted        += RunWorkerCompleted;

            worker.RunWorkerAsync();

            eventObject.ActionPerformed += ActionPerformed;
        }
Esempio n. 3
0
        public vwMenager GetMenagerByName(string name)
        {
            try
            {
                using (EmployeeDBEntities context = new EmployeeDBEntities())
                {
                    vwMenager menager = (from m in context.vwMenagers where m.Menager.Equals(name) select m).First();


                    return(menager);

                    //FileLoging fileLog = FileLoging.Instance();
                    //fileLog.LogDeleteUserToFile(userToDelete);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public AddEmployeeViewModel(AddEmployee addEmployeeOpen)
        {
            eventObject     = new EventClass();
            selctedLocation = new vwLOCATION();
            selectedMenager = new vwMenager();
            employee        = new vwEmployee();
            addEmployee     = addEmployeeOpen;

            locationService = new LocationService();
            employeeService = new EmployeeService();
            genderService   = new GenderService();
            sectorService   = new SectorService();

            LocationList = locationService.GetAllLocations().ToList();
            LocationList.OrderByDescending(x => x.Location);
            LocationList.Reverse();



            PotentialMenagers = employeeService.GetAllPotentialMenagers();


            eventObject.ActionPerformed += ActionPerformed;
        }
Esempio n. 5
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());
            }
        }