コード例 #1
0
        public void InitDepartments()
        {
            Log.InfoStart("InitDepartments");

            LocationCardToPersonnels.Clear();
            Personnels.Clear();
            Departments.Clear();

            Department dep0 = new Department()
            {
                Name = "根节点", ShowOrder = 0, Parent = null, Type = DepartType.本厂
            };

            Departments.Add(dep0);
            Department dep11 = new Department()
            {
                Name = "四会电厂", ShowOrder = 0, Parent = dep0, Type = DepartType.本厂
            };

            Departments.Add(dep11);
            Department dep12 = new Department()
            {
                Name = "维修部门", ShowOrder = 0, Parent = dep11, Type = DepartType.本厂
            };

            Departments.Add(dep12);//单个添加可以只是设置Parent
            Department dep13 = new Department()
            {
                Name = "发电部门", ShowOrder = 1, ParentId = dep11.Id, Type = DepartType.本厂
            };                                                                                                              //批量添加必须设置ParentId
            Department dep14 = new Department()
            {
                Name = "外委人员", ShowOrder = 2, ParentId = dep11.Id, Type = DepartType.本厂
            };
            Department dep15 = new Department()
            {
                Name = "访客", ShowOrder = 0, ParentId = dep11.Id, Type = DepartType.本厂
            };

            List <Department> subDeps = new List <Department>()
            {
                dep12, dep13, dep14, dep15
            };
            List <Department> subDeps2 = new List <Department>()
            {
                dep13, dep14, dep15
            };

            Departments.AddRange(subDeps2);

            //Departments.AddRange(dep11, dep12, dep13, dep14, dep15);

            Posts.Clear();
            Post post1 = new Post()
            {
                Name = "前台"
            };
            Post post2 = new Post()
            {
                Name = "电工"
            };
            Post post3 = new Post()
            {
                Name = "维修工"
            };
            Post post4 = new Post()
            {
                Name = "保安"
            };
            Post post5 = new Post()
            {
                Name = "经理"
            };
            Post post6 = new Post()
            {
                Name = "电工"
            };
            Post post7 = new Post()
            {
                Name = "访客"
            };
            var posts = new List <Post>()
            {
                post1, post2, post3, post4, post5, post6, post7
            };

            Posts.AddRange(posts);
            List <LocationCard> tagsT = LocationCards.ToList();
            RandomTool          rt    = new RandomTool();

            for (int i = 0; i < maxPersonCount && i < tagsT.Count; i++)
            {
                var tag = tagsT[i];
                //int n = r.Next(1);
                int n    = i % 2;
                var post = posts[r.Next(posts.Count)];
                var dep  = subDeps[r.Next(subDeps.Count)];
                if (n == 0)
                {
                    AddPerson(rt.GetWomanName(), Sexs.女, tag, dep, post, i, rt.GetRandomTel());
                }
                else
                {
                    AddPerson(rt.GetManName(), Sexs.男, tag, dep, post, i, rt.GetRandomTel());
                }
            }
        }
コード例 #2
0
        private void AddPerson(string name, Sexs sex, LocationCard tag, Department dep, Post pst, int worknumber, string phone)
        {
            Personnel person = new Personnel()
            {
                Name       = name,
                Sex        = sex,
                Enabled    = true,
                ParentId   = dep.Id,
                WorkNumber = worknumber,
                Phone      = phone,
                Pst        = pst.Name
            };

            Personnels.Add(person);


            if (tag != null && person != null)
            {
                LocationCardToPersonnel cardToPerson = new LocationCardToPersonnel();
                cardToPerson.PersonnelId    = person.Id;
                cardToPerson.LocationCardId = tag.Id;
                LocationCardToPersonnels.Add(cardToPerson);
            }
        }