Return a subset of a List of objects in vb.net

2019-08-29 09:04发布

I feel like there is a more simple way then anything I am thinking of right now to do this..

So I am going to lay some groundwork here:

  • I have an Organization which has Departments stored as a List(of Department)
  • The Departments has Person which is stored as a List(of Person)
  • Each person has a Calendar in it which is a List(of Dictionary(String, String))

The short reason why is people do not want to upgrade to databases and I have to make do with pulling the data from an Excel table and manipulating the data to make a manning chart.

Now the issue I am having is that I need to scour the Organization across all Departments to select only Persons who's Calendar says they should be assigned to that Department for the day.

I can select their calendar status as follows:

If (person.Cal(dateOffset).Item("status") = Right(departmentName, 1) & ".") Then

So to make this more clear.. the calendar works as follows: They select a date range in the GUI. The program finds the first date listed (a constant location in the Excel Table) and then does a date diff to get the dateOffset. That becomes the Excel Jump to number to lookup the dates. I am storing the cell color, cell text ("status") and cell comment in the Dictionary.

If they are assigned to a different department that day (where the departments could be DA, DB, DC, DD etc) they put A., B., C., D. and I have to parse the difference. Keep in mind this function works flawlessly. I am restructuring the code to make this dynamic and a lot less hard coded stuff as I have right now, a little less code, and less things running in memory.

Now the dilemma, the I need to access this information from the List and I'm hoping there is a way I don't have to do a for loop to do it since that is currently the way I am doing it. Is there a way to make a sub list from the full list of personnel that only returns people who's calendar status is equal to a value. I think the term is Lambda but whatever the term is I'm hoping for a solution like that. Thanks in advance.

Note: sorry I did not produce much code but there is a lot going on in there and the code is not releasable.

0条回答
登录 后发表回答