0 Replies - 1457 Views - Last Post: 24 March 2010 - 11:33 AM Rate Topic: -----

#1 AtlasIV  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-January 10

Display and report the results of a LINQ ArrayList query

Posted 24 March 2010 - 11:33 AM

Hello,
I am almost finished writing a time log program which allows users to input the date, start time, end time, funding source, billing code, client, state of service, etc. for each type of service they provide throughout the week. They can input up to 40 rows of data and I am trying to summarize and filter this data in a number of ways (I did not include this code as it is working fine, but could upon request to show I've done the work). I believe I have finally written a working query to summarize total hours worked but want to view the results before writing queries for the rest of the summary data I need. Right now, I am having difficulty viewing the results of the query. I have tried displaying them in a combobox using simple and complex data binding with the same error (location and type of error noted below). Please let me know if you have any suggestions for improving the way I am trying to 1) display the results of the query in the form as well as write the results to a file or 2) query the entered data in the first place:




Imports System
Imports System.IO
Imports System.Collections
Imports System.Linq
Imports System.Diagnostics


Public Class qRow
        Public ServiceDate As Date
        Public StartTime As String
        Public EndTime As String
        Public Total As Integer()
        Public FundingSource As String
        Public Client As String
        Public Code As String
        Public Description As String
        Public State As String
        Public Notes As String
    End Class




'This sub is initiated by a button press at the moment
Public Sub Main()

        Dim qRow1 As New qRow With {.ServiceDate = dtp1.Value, _
                                     .StartTime = cbxStartHour1.Text & ":" & cbxStartMin1.Text, _
                                     .EndTime = cbxEndHour1.Text & ":" & cbxEndMin1.Text, _
                                     .Total = New Integer() {txtTotal1.Text}, _
                                     .FundingSource = cbxFund1.Text, _
                                     .Client = txtClient1.Text, _
                                     .Code = cbxCode1.Text, _
                                     .Description = txtDescript1.Text, _
                                     .State = txtState1.Text, _
                                     .Notes = txtNotes1.Text}
        Dim qRow2 As New qRow With {.ServiceDate = dtp2.Value, _
                                     .StartTime = cbxStartHour2.Text & ":" & cbxStartMin2.Text, _
                                     .EndTime = cbxEndHour2.Text & ":" & cbxEndMin2.Text, _
                                     .Total = New Integer() {txtTotal2.Text}, _
                                     .FundingSource = cbxFund2.Text, _
                                     .Client = txtClient2.Text, _
                                     .Code = cbxCode2.Text, _
                                     .Description = txtDescript2.Text, _
                                     .State = txtState2.Text, _
                                     .Notes = txtNotes2.Text}
        Dim qRow3 As New qRow With {.ServiceDate = dtp3.Value, _
                                     .StartTime = cbxStartHour3.Text & ":" & cbxStartMin3.Text, _
                                     .EndTime = cbxEndHour3.Text & ":" & cbxEndMin3.Text, _
                                     .Total = New Integer() {txtTotal3.Text}, _
                                     .FundingSource = cbxFund3.Text, _
                                     .Client = txtClient3.Text, _
                                     .Code = cbxCode3.Text, _
                                     .Description = txtDescript3.Text, _
                                     .State = txtState3.Text, _
                                     .Notes = txtNotes3.Text}
                         '(etc. - there are 40 rows)

Dim arrROWS As New ArrayList()
        arrROWS.Add(qRow1)
        arrROWS.Add(qRow2)
        arrROWS.Add(qRow3)
                        '(etc.)

End Sub


I have been able to use the following query to count how many rows contain a specific funding source and view the results)
Dim count = Aggregate qRow In arrROWS Into Count(qRow.FundingSource = "FNRC")
ME.text = count

'This query does not throw any errors, but I cannot figure out how to display the resulting total:
Dim totalhours = From qRow In arrROWS _
                         Group qRow By qRow.fundingsource Into Group _
                         Select fundingsource, total = Group.Sum(Function(qRow) qRow.total)

'Here is my latest attempt:
        cbxDataBind.DataSource = totalhours
        ''''ERROR occurs on the line above: ArgumentException was unhandled, "Complex DataBinding accepts as a data source either an IList or an IListSource." 
        cbxDataBind.DisplayMember = "Total Hours"


'Here is a sample of the writeline code - I will write up to 40 rows if data is entered in them and I want the query results at the end:
FileOpen(1, "C:\TimeLogs\" & txtName.Text & Now.ToString("MMddyyyy") & "(RawData).txt", OpenMode.Append)
        WriteLine(1, "Week Start", calStart.Text, "Week End", calEnd.Text, "saved on", Date.Now)
        WriteLine(1, "Date", "Start Time", "End Time", "Total Time", "Funding Source", "Client", "Code", "Description", "State", "Notes")
        WriteLine(1, dtp1.Text, cbxStartHour1.Text & ":" & cbxStartMin1.Text & cbxStartDay1.Text, cbxEndHour1.Text & ":" & cbxEndMin1.Text & cbxEndDay1.Text, txtTotal1.Text, cbxFund1.Text, txtClient1.Text, cbxCode1.Text, txtDescript1.Text, txtState1.Text, txtNotes1.Text)
        WriteLine(1, "Total Hours", totalhours)






Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1