Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a report for shifting schedule on every 8hours.my system has a login form which is when you login,it will save the time you currently login same with the logout.but in my problem,i was just testing to display the records (first) of the loghistory like this:

Name:username field
Date:currentdate
Shift Start:loggedin field ------ this is were im having a problem.it only display the first record not the current time i have loggedin.
Shift Ends:loggedout field


this my code in my form:

If ComboBox1.Text = "Shift 1" Then
Dim rpt As New EndofShift() 'The report you created.
Dim MyCommand As New SqlCommand()
Dim myDS2 As New loghistory() 'The DataSet you created.
Dim myDA2 As New SqlDataAdapter()
Dim myDS As New DSactualguesting() 'The DataSet you created.
Dim myDA As New SqlDataAdapter()
Dim cn As New SqlConnection(ConnectString())

Try

MyCommand.Connection = cn
MyCommand.CommandText = "Select * from loghistory where username='" + Login.txtuser.Text + "'"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "loghistory")

myDS.EnforceConstraints = False
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try


End If
Posted
Comments
Chester Costa 13-Jun-13 22:03pm    
i updated my code like this:

If ComboBox1.Text = "Shift 1" Then
Dim rpt As New EndofShift() 'The report you created.
Dim MyCommand As New SqlCommand()
Dim myDS2 As New loghistory() 'The DataSet you created.
Dim myDA2 As New SqlDataAdapter()
Dim myDS As New DSactualguesting() 'The DataSet you created.
Dim myDA As New SqlDataAdapter()
Dim cn As New SqlConnection(ConnectString())
Dim dt As DateTime = "06:00:00AM"
Dim dt2 As DateTime = "02:00:00PM"
Try

MyCommand.Connection = cn
MyCommand.CommandText = "Select * from actualguesting"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "actualguesting")

myDA.SelectCommand.CommandText = "Select username,loggedin,loggedout from loghistory where username='" + Login.txtuser.Text + "' order by loggedin "
myDA.Fill(myDS, "loghistory")

myDS.EnforceConstraints = False
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End If


my formula in summing up the total sales between 6AM to 2pm is like this:
if {loghistory.username}='ches' and
{loghistory.loggedin}>= datetimevalue(CurrentDate,Time (05,59 ,59 )) to
datetimevalue(CurrentDate,Time (13,59 ,59 ))
and
{actualguesting.paymentmode}='CASH'
then
sum({actualguesting.totalamount})


when i run the report,it sum up all the records but not in the time i logged in
Surendra Adhikari SA 14-Jun-13 0:52am    
have you solved it?? whats the problems?
Chester Costa 14-Jun-13 4:39am    
i want to sum records between 8:00Am to 2:00PM. there are three shifts in a day so i was trying to sum the records between the first record.

1 solution

Try limiting fetched data as of your requirement.
you can concat your condition in query . So It is easy to debug and see the result fetched then writing formula in report.that is :

VB
MyCommand.CommandText = "Select username,currentdate,loggedin,loggedout from loghistory where username='" + Login.txtuser.Text + "' where  loggedin > 'date of shift' and loggedout > 'date of shift ' ....etc  order by currentdate desc  "



you have so less detail about your logic and error you found ,only code is not enough to fill your actual problem. you should be more descriptive .

Debug and view data fetched in your dataset myDS.
Is myDS have values as of your condition ?
what table actualguesting holds?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900