开发者

Tracking assigned object assignments

A project I'm working on requires me to solve the following problem for a simulation program:

The program pulls from sql 2 separate distinct lists. As an example I'll use "Employees" and "Tasks". We then programmatically assign anywhere from 0-2 "Employees" per "Task". Each employee can be assigned to more then one task, but some tasks may require multiple employees and some tasks may go unassigned.

This all happens at the C# level and wont be stored back to sql, after the assignments the program resolves the simulation by resolving the results of individual assignments, stores results and runs the next set of lists.

I don't need to manage lists beyond a size of 10-15 max, but need a solution efficient enough that a can batch run several thousand sims with out the assignment solution getting in the way.

I have quite a bit of flexibility, since at this point the objects are simply listitems direct开发者_StackOverflow from sql.

(I'm not a professional programmer so this might be obvious, or impossible)


This is easily done using generics.

    public class Employee
    {
        public string EmployeeName;
        public string EmployeeID;
    }

    public class Task
    {
        public string TaskName;
        public List<Employee> EmployeeList = new List<Employee>();
    }

    public void TestTaskList()
    {
        // list of tasks.
        List<Task> m_TaskList = new List<Task>();
        // create a new task.
        Task oFirstTask = new Task { TaskName = "First Task" };
        // add this task to your list
        m_TaskList.Add(oFirstTask);
        // loop through your tasks.
        foreach( Task oTask in m_TaskList) {
            if (oTask.EmployeeList.Count() == 0) 
                // there are no employees, so add one
                oTask.EmployeeList.Add(
                    new Employee { EmployeeName = "mschietinger" }
                    );
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜