Exemplo n.º 1
0
        /// <summary>
        /// 根据部门取出上下级关系,构建部门和负责人kv
        /// </summary>
        /// <param name="departments"></param>
        private void generateCustomResource(List <String> departments)
        {
            Dictionary <String, List <EmpDto> > keyValuePairs = new Dictionary <String, List <EmpDto> >();

            foreach (String department in departments)
            {
                keyValuePairs.Add(
                    department
                    , EmpService.findByDepartment(department)
                    );
            }   //  部门和员工kv


            int          i      = 0;
            List <Color> Colors = new ResouceColorUtil().Colors; //  资源颜色工具类

            foreach (string department in keyValuePairs.Keys)
            {
                foreach (EmpDto empDto in keyValuePairs[department])
                {  //  员工
                    if (this.departmentAndCustomResource.ContainsKey(department))
                    {
                        //  更新
                        Boolean conflict = false;   //  id重复
                        foreach (CustomResource customResource in this.departmentAndCustomResource[department])
                        {
                            if (empDto.Id.Equals(customResource.ResID))
                            {
                                conflict = true;
                                break;  //  去重
                            }
                        }
                        if (!conflict)
                        {
                            this.departmentAndCustomResource[department].Add(new CustomResource(empDto.Id, empDto.Name, Colors[++i]));
                        }
                    }
                    else
                    {
                        //  新增
                        BindingList <CustomResource> customResources = new BindingList <CustomResource>();
                        customResources.Add(new CustomResource(empDto.Id, empDto.Name, Colors[++i]));
                        this.departmentAndCustomResource.Add(department, customResources);
                    }
                }
            }
        }