views:

36

answers:

2

I have a application which is on timesheet. I have total of 54 columns out of which 10 columns are visible rest invisible.

First 3 columns are Project, MileStone and Classes. Rest are Sun- Sat work hrs, TaskId, TaskDesc and so on for each day. On my grid only first 3 columns and Sun - Sat work hrs are visible, rest are invisible.

These Columns from Sun - Sat do not exists in database. They are identified on the basis of date and displayed on the grid. They exists as row in database but displayed as column over the grid.

Now I have columns named SunTaskID,MonTaskID and so on till SatTaskID for holding each days taskid[TaskID is the PK of the table from which data is pulled out. And each has its own task id.] Now on the selection of SunHrs (Sunday's Work Hrs), i retrieve that days taskid and on the basis of task id i then retrieve attachments which is displayed under a listbox.

Now the problem is that since a day can have multiple attachments and a user can attach multiple attachments at time. I am not able to hold the attachments.

For example

Project | Milestone | Class | Sunhrs | Monhrs | TueHrs | WedHrs | ThuHrs | FriHrs | satHrs 

abc - xyz |sa       | nyz   | 11.00  | 6.00      | 0     | 0       |1      |1       | 0

abc - xyz |sa       | dasdds| 1.00  | 9.00      | 16   | 10 _      |11      |11       | 10

Attachments
---------------------
|
| abc.txt
| def.pdf
|
|
|____________________

Say above is my grid and below grid, is attachment, its a listbox to hold attachments. _ is my current cursor location which is at WedHrs having value 10 [second row].

I am using BindingList(of TaskClass) in VB.Net for binding grid. I have total 54 properties n my task class. I have only 10 columns visible rest invisible whose values are retrieved programatically.

Current cell has attachment abc.txt and def.pdf. The problem is that i need to attach attachments to multiple cells before saving. But i am not able to hold. I have my task model having all properties for grid. I then on save iterates the collection and retrieves the values for each required item.

But for attachments here i need some sort of collection property in my taskmodel class to hold attachments for all days of a row.

Earlier I tried Dictionary. But i was not aware of its usage as a property so i gave. Then prepared a separate class for attachment but, it was difficult to synchronize the existing attachments with taskid...

I hope now the issue will be clear

A: 

I'm not sure that I understand your question, but at least part of it seems to ask for a collection to store the attachments in. I'd suggest just having a dictionary with the taskID as the key and a list as the value and so you can link multiple attachments to one taskID.

Dim attachments As Dictionary(Of Int32, List(Of Object))
ho1
+1  A: 

I hope i have now nearly understood what you want to achieve. Would it be helpful for you to know the Tasks(attachments) for any day? Also, is it possible for users to add/remove attachments task-indepent/task-comprehensive for a special day? If this is not the case and answer to first question is yes(otherwise it hopefully brings you back on track): When loading Tasks from database and initializing your TaskClass-Objects you could add this objects to a shared Dictionary in your TaskClass which key is the date and value is a list of Tasks.

An example:

   Private Sub loadForm(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Task.loadData("only for test case")

        Dim testDate As Date = New Date(2010, 5, 19) 'today, wednesday as in your example
        'now i want all tasks and attachments for this day
        If Task.allDayTasks.ContainsKey(testDate) Then
            Dim allTasksForThisDay As List(Of Task) = Task.allDayTasks(testDate)
            Dim allAttachmentsForThisDay As New List(Of Task.TaskAttachment)
            For Each task As Task In allTasksForThisDay
                For Each attachment As Task.TaskAttachment In task.allAttachments
                    allAttachmentsForThisDay.Add(attachment)
                Next
            Next

            For Each attachment As Task.TaskAttachment In allAttachmentsForThisDay
                Console.WriteLine(attachment.file)
            Next
        End If
    End Sub

    Class Task
        Public Shared allDayTasks As New Dictionary(Of Date, List(Of Task))
        Public taskID As String
        Public allAttachments As New List(Of TaskAttachment)
        Public begin As Date
        Public duration As Int32 'f.e. hours

        Shared Function loadData(ByVal taskID As String) As Task
            'Do your database stuff to get the Task and its attachments
            Dim newTask As New Task
            newTask.taskID = taskID
            newTask.begin = New Date(2010, 5, 19)
            newTask.duration = 10
            '...........
            newTask.allAttachments.Add(New TaskAttachment("abc.txt"))
            newTask.allAttachments.Add(New TaskAttachment("def.pdf"))

            If allDayTasks.ContainsKey(newTask.begin) Then
                'Equals overridden to use contains and indexof
                If allDayTasks(newTask.begin).Contains(newTask) Then
                    Dim taskIndex As Int32 = allDayTasks(newTask.begin).IndexOf(newTask)
                    allDayTasks(newTask.begin)(taskIndex) = newTask
                Else
                    allDayTasks(newTask.begin).Add(newTask)
                End If
            Else
                Dim dayTasks As New List(Of Task)
                dayTasks.Add(newTask)
                allDayTasks.Add(newTask.begin, dayTasks)
            End If

            Return newTask
        End Function

        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            If obj Is Nothing Then
                Return False
            Else
                Return Me.ToString.Equals(obj.ToString)
            End If
        End Function

        Public Overrides Function ToString() As String
            Return Me.taskID.ToString()
        End Function

        Class TaskAttachment
            Sub New(ByVal file As String)
                Me.file = file
            End Sub
            Public file As String
        End Class
    End Class
Tim Schmelter
Thanks tim , u were close but not what I am expecting. Anyways 1 up for the solutions. It helped me in some other aspects. Busy with same stuff will put some more details regarding the query afterwards...
Amit Ranjan