Esempio n. 1
0
        /// <summary>
        /// Adds this company to the given sector if it has not been added
        /// already. Also checks sector aliases of all sectors the company
        /// is already added to.
        /// </summary>
        public void AddToSectorIfNew(Sector sector)
        {
            if (Sectors.FirstOrDefault(s => s.Name == sector.Name) != null)
            {
                return;
            }

            if (Sectors.SelectMany(s => s.Aliases).FirstOrDefault(a => a.Name == sector.Name) != null)
            {
                return;
            }

            Sectors.Add(sector);
        }
        private void SaveExecute()
        {
            try
            {
                var db = new DataAccess();
                Employee.Surname            = Surname;
                Employee.GivenName          = GivenName;
                Employee.LocationID         = Location.LocationID;
                Employee.Sex                = Sex.ToLower();
                Employee.PersonalNo         = PersonalNo;
                Employee.DateOfBirth        = GeneratingData.GenerateBirthdate(Employee.PersonalNo);
                EmployeeAge                 = GeneratingData.CalculateAge(Employee.DateOfBirth);
                Employee.Manager            = Manager;
                Employee.Telephone          = Telephone;
                Employee.RegistrationNumber = RegistrationNumber;
                if (Sectors.Any(s => s.Name == SectorName))
                {
                    Employee.SectorID = Sectors.First(s => s.Name == SectorName).SectorID;
                }
                else
                {
                    var newSector = new tblSector()
                    {
                        Name = SectorName
                    };
                    //adding new sector to database
                    db.AddNewSector(newSector);
                    Sectors           = LoadSectors();
                    Employee.SectorID = Sectors.FirstOrDefault(s => s.Name == SectorName).SectorID;
                }

                //updating employee
                db.UpdateEmployee(Employee.EmployeeID, Employee);

                workerUpdate.RunWorkerAsync();

                IsUpdatedEmployee = true;
                updateEmployeeView.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public UpdateEmployeeViewModel(UpdateEmployeeView updateEmployeeView, tblEmployee selectedEmployee)
        {
            workerUpdate.DoWork    += LogUpdatedEmployee;
            this.updateEmployeeView = updateEmployeeView;
            Sectors              = LoadSectors();
            Managers             = LoadManagers(selectedEmployee.EmployeeID);
            Locations            = LoadLocations();
            Employee             = new tblEmployee();
            PreviousEmployeeData = new tblEmployee();
            Surname              = selectedEmployee.Surname;
            GivenName            = selectedEmployee.GivenName;
            PersonalNo           = selectedEmployee.PersonalNo;
            Telephone            = selectedEmployee.Telephone;
            RegistrationNumber   = selectedEmployee.RegistrationNumber;
            Sex        = selectedEmployee.Sex;
            Manager    = selectedEmployee.Manager;
            Sector     = Sectors.FirstOrDefault(s => s.SectorID == selectedEmployee.SectorID);
            SectorName = Sectors.FirstOrDefault(s => s.SectorID == selectedEmployee.SectorID).Name;
            Location   = Locations.FirstOrDefault(x => x.LocationID == selectedEmployee.LocationID);

            Employee.EmployeeID         = selectedEmployee.EmployeeID;
            Employee.GivenName          = selectedEmployee.GivenName;
            Employee.Surname            = selectedEmployee.Surname;
            Employee.PersonalNo         = selectedEmployee.PersonalNo;
            Employee.LocationID         = selectedEmployee.LocationID;
            Employee.Sex                = selectedEmployee.Sex;
            Employee.RegistrationNumber = selectedEmployee.RegistrationNumber;
            Employee.SectorID           = selectedEmployee.SectorID;
            Employee.Telephone          = selectedEmployee.Telephone;
            Employee.Manager            = selectedEmployee.Manager;

            //keeping previous client data in property
            PreviousEmployeeData.GivenName          = selectedEmployee.GivenName;
            PreviousEmployeeData.Surname            = selectedEmployee.Surname;
            PreviousEmployeeData.PersonalNo         = selectedEmployee.PersonalNo;
            PreviousEmployeeData.LocationID         = selectedEmployee.LocationID;
            PreviousEmployeeData.Sex                = selectedEmployee.Sex;
            PreviousEmployeeData.RegistrationNumber = selectedEmployee.RegistrationNumber;
            PreviousEmployeeData.SectorID           = selectedEmployee.SectorID;
            PreviousEmployeeData.Telephone          = selectedEmployee.Telephone;
            PreviousEmployeeData.Manager            = selectedEmployee.Manager;

            CanSave = true;
        }
        private void SaveExecute()
        {
            try
            {
                var db = new DataAccess();
                Employee.Sex = Sex.ToLower();
                Employee.RegistrationNumber = RegistrationNumber;
                Employee.PersonalNo         = PersonalNo;
                Employee.LocationID         = Location.LocationID;
                Employee.DateOfBirth        = GeneratingData.GenerateBirthdate(Employee.PersonalNo);
                if (Sectors.Any(s => s.Name == SectorName))
                {
                    Employee.SectorID = Sectors.First(s => s.Name == SectorName).SectorID;
                }
                else
                {
                    var newSector = new tblSector()
                    {
                        Name = SectorName
                    };
                    //adding new sector to database
                    db.AddNewSector(newSector);
                    Sectors           = LoadSectors();
                    Employee.SectorID = Sectors.FirstOrDefault(s => s.Name == SectorName).SectorID;
                }


                //adding new employee to database
                db.AddNewEmployee(Employee);

                workerAddNew.RunWorkerAsync();

                IsAddedNewEmployee = true;

                addNewEmployeeView.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 5
0
 public Section GetSector(double x, double y)
 {
     return(Sectors.FirstOrDefault(s => s.Inside(x, y)));
 }
 private string GetPreviousEmployeeSectorName()
 {
     return(Sectors.FirstOrDefault(s => s.SectorID == PreviousEmployeeData.SectorID).Name);
 }
Esempio n. 7
0
 public Sector GetSector(string id)
 => Sectors?.FirstOrDefault(x => x.Id == id);