My problem is that I want a grid that is populated with a set of times spent on tasks. It needs to have the days of the week at the top (these would preferably be fixed – i.e. Sun, Mon… Sat) and task names down the left column. The contents of the grid will have the individual hours spent for that day on that task.
What would the best approach to take to achieve this? Option one would be to try and put it all in SQL statements in the database. Option two is a collection of LINQ queries that pull raw data from a Tasks and TimeEntries and structure it correctly. Option three is to use LINQ and pull the results into a class (or collection), which is then bound to the control (probably a gridview).
How would you do this?
I’ll take a rough hack at it not knowing your structure but guessing you have a task table and a tasktime table that stores the actual times and dates that are charged to each task. This isn’t tested but:
select t.taskname, sum(case when datepart(d,tt.taskdate)= 1, tt.taskhours) else 0 end) as Sunday, sum(case when datepart(d,tt.taskdate)= 2, t.taskhours) else 0 end) as Monday from tasktable t join tasktime tt on t.taskid = tt.taskid where tt.taskdate >= @begindate and tt.taskdate<= @enddate
The where clause is important because you probably only want to display a week at time (usually the current week) on your grid. This also assumes you have properly stored the ddates of your hours charged as datetime data type. (if you haven’t fix that now – you will thank me later.) The variables would be submitted from the user interface in some fashion. I personally would do that as a stored proc. I left Tues through Saturday for you to do.