Exemple #1
0
        //just generate some sample data...
        public void PopulateWithSampleData(int count, bool multipleRootNodes)
        {
            Random r = new Random(12313);

            this._Employeelist = new List <EmployeeInfo>();
            //just generate to randon data in some manner - not really related to the TreeGrid itself...
            PopulateWithFlatData(count);

            //now need to set up the reportsto property...
            // first create a list of all the employees
            List <int> all = new List <int>();

            for (int i = 0; i < count; ++i)
            {
                all.Add(i);
            }

            //choose 2 big bosses - with half the employees reporting to each...

            //first big boss
            int          randonLocation = r.Next(all.Count);
            int          parentID       = all[randonLocation];
            EmployeeInfo bigBoss        = this.Employeelist[parentID];

            bigBoss.FirstName = "BIGBOSS1";
            bigBoss.Salary    = 200000d;
            bigBoss.ReportsTo = -1; //big boss reports to no one

            //remove boss for pool
            all.Remove(parentID);
            List <EmployeeInfo> employeesToProcess = new List <EmployeeInfo>();

            employeesToProcess.Add(bigBoss);

            //now loop through and set direct reports to this parent
            int half = multipleRootNodes ? all.Count / 2 : 0;

            while (all.Count > half)
            {
                List <EmployeeInfo> nextSetToProcess = new List <EmployeeInfo>();
                foreach (EmployeeInfo e in employeesToProcess)
                {
                    int numberOfReports = r.Next(6) + 1;
                    while (numberOfReports > 0 && all.Count > half)
                    {
                        randonLocation = r.Next(all.Count);
                        int          childID = all[randonLocation];
                        EmployeeInfo child   = this.Employeelist[childID];
                        nextSetToProcess.Add(child);
                        child.ReportsTo = e.ID;
                        numberOfReports--;
                        all.Remove(childID);
                    }
                    if (all.Count <= half)
                    {
                        break;
                    }
                }
                employeesToProcess = nextSetToProcess;
            }

            if (multipleRootNodes)
            {
                //second big boss
                randonLocation    = r.Next(all.Count);
                parentID          = all[randonLocation];
                bigBoss           = this.Employeelist[parentID];
                bigBoss.FirstName = "BIGBOSS2";
                bigBoss.Salary    = 200000d;
                bigBoss.ReportsTo = -1; //big boss reports to no one

                //remove boss for pool
                all.Remove(parentID);

                employeesToProcess = new List <EmployeeInfo>();
                employeesToProcess.Add(bigBoss);

                //now loop through and set direct reports to this parent

                while (all.Count > 0)
                {
                    List <EmployeeInfo> nextSetToProcess = new List <EmployeeInfo>();
                    //employeesToProcess.Sort();
                    foreach (EmployeeInfo e in employeesToProcess)
                    {
                        int numberOfReports = r.Next(6) + 1;
                        while (numberOfReports > 0 && all.Count > 0)
                        {
                            randonLocation = r.Next(all.Count);
                            int          childID = all[randonLocation];
                            EmployeeInfo child   = this.Employeelist[childID];
                            nextSetToProcess.Add(child);
                            child.ReportsTo = e.ID;
                            numberOfReports--;
                            all.Remove(childID);
                        }
                        if (all.Count == 0)
                        {
                            break;
                        }
                    }
                    employeesToProcess = nextSetToProcess;
                }
            }

            Employeelist.Sort();
        }
Exemple #2
0
 /// <summary>
 /// Gets the item bitmap.
 /// </summary>
 /// <param name="emp">The emp.</param>
 /// <returns></returns>
 public BitmapImage GetItemBitmap(EmployeeInfo emp)
 {
     return(images[emp.ImageIndex]);
 }