Пример #1
0
        /// <summary>
        /// Get a stack of employees, starting with the employee passed in and ending with the topmost manager
        /// </summary>
        /// <param name="emp"></param>
        /// <param name="employeeList"></param>
        /// <returns></returns>
        private Stack <EmployeeNode> getEmployeeStack(Employee emp, List <Employee> employeeList)
        {
            Stack <EmployeeNode> nodeStack = new Stack <EmployeeNode>();
            EmployeeNode         node      = new EmployeeNode(emp);

            nodeStack.Push(node);
            Employee current = emp;

            while (current.ManagerId.HasValue)
            {
                current = employeeList.FirstOrDefault(x => x.EmployeeId == current.ManagerId.Value);
                EmployeeNode managerNode = new EmployeeNode(current);
                nodeStack.Push(managerNode);
            }
            return(nodeStack);
        }
        public DayOfSalaryGiveoutReportViewModel(
            RdlViewerViewModel rdlViewerViewModel,
            ICommonServices commonServices
            ) : base(rdlViewerViewModel)
        {
            Title      = "Дата выдачи ЗП водителей и экспедиторов";
            Identifier = "Cash.DayOfSalaryGiveout";

            _interactiveService = (commonServices ?? throw new ArgumentNullException(nameof(commonServices))).InteractiveService;
            var hasAccess = commonServices.CurrentPermissionService.ValidatePresetPermission("has_access_to_next_salary_day_report");

            if (!hasAccess)
            {
                throw new AbortCreatingPageException("Нет права на просмотр этого отчета", "Недостаточно прав");
            }

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot())
            {
                EmployeeNode resultAlias   = null;
                Employee     employeeAlias = null;

                EmployeeNodes = uow.Session.QueryOver(() => employeeAlias)
                                .Where(() => employeeAlias.Status != EmployeeStatus.IsFired &&
                                       employeeAlias.Status != EmployeeStatus.OnCalculation &&
                                       (employeeAlias.Category == EmployeeCategory.driver ||
                                        employeeAlias.Category == EmployeeCategory.forwarder) &&
                                       !employeeAlias.VisitingMaster
                                       )
                                .SelectList(list => list
                                            .Select(() => employeeAlias.Id).WithAlias(() => resultAlias.Id)
                                            .Select(() => employeeAlias.Name).WithAlias(() => resultAlias.Name)
                                            .Select(() => employeeAlias.LastName).WithAlias(() => resultAlias.LastName)
                                            .Select(() => employeeAlias.Patronymic).WithAlias(() => resultAlias.Patronymic)
                                            .Select(() => employeeAlias.Category).WithAlias(() => resultAlias.Category)
                                            )
                                .OrderBy(e => e.LastName).Asc.ThenBy(x => x.Name).Asc
                                .TransformUsing(Transformers.AliasToBean <EmployeeNode>())
                                .List <EmployeeNode>();
            }
        }
Пример #3
0
        /// <summary>
        /// Get a tree of employees for each employee with null ManagerId
        /// </summary>
        /// <returns></returns>
        public List <EmployeeNodeTree> GetEmployeeNodeTree()
        {
            List <Employee>                employees   = _context.Employees.ToList();
            List <EmployeeNodeTree>        list        = new List <EmployeeNodeTree>();
            Dictionary <int, EmployeeNode> employeeMap = new Dictionary <int, EmployeeNode>();

            foreach (var emp in employees)
            {
                if (employeeMap.ContainsKey(emp.EmployeeId))
                {
                    //Node has already been added so no action needed
                    continue;
                }

                // Get a stack of employees, starting with the employee passed in and ending with the topmost manager
                Stack <EmployeeNode> employeeStack = getEmployeeStack(emp, employees);


                //Get topmost manager
                EmployeeNode current = employeeStack.Pop();

                if (!employeeMap.ContainsKey(current.EmployeeId))
                {
                    //If topmost manager is not already added, create a new tree
                    list.Add(new EmployeeNodeTree
                    {
                        root = current
                    }
                             );
                    //Add empty node to map
                    employeeMap[current.EmployeeId] = current;
                }
                else
                {
                    //Current node already exists in a tree so use that instead of empty one
                    current = employeeMap[current.EmployeeId];
                }

                EmployeeNode currentManager = current;

                while (employeeStack.Count > 0)
                {
                    current = employeeStack.Pop();
                    if (!employeeMap.ContainsKey(current.EmployeeId))
                    {
                        //Add empty node to map
                        employeeMap[current.EmployeeId] = current;
                    }
                    else
                    {
                        //Current node already exists in a tree so use that instead of empty one
                        current = employeeMap[current.EmployeeId];
                    }

                    //If manager does not already have this employee as a child, add it.
                    if (!currentManager.Children.Any(x => x.EmployeeId == current.EmployeeId))
                    {
                        currentManager.Children.Add(current);
                    }

                    currentManager = current;
                }
            }
            return(list);
        }