Hello
I'm making an script so that the employees can register the hours that they have worked. The script is like this, the employee selects on a dropdown, the project that he is working, the start time and the end time.
For example, he selects "Project 1" from "8:00" to "10:00"
Ok.. until here, it's fine..
But, he can't after this, put something like
"Project 2" from "9:00" to "9:30"
got it ?
Because, if he was working on the Project 1 from 8AM to 10AM, he couldn't be working also on Project 2 between 9AM to 9:30AM
I tried to put something like
while not rs.eof
flag = FALSE
IF starttime > rs("starttime") THEN
flag = TRUE
END IF
IF endtime < rs("endtime") AND flag = TRUE then
response.write "You can't register two hours at the same time"
END IF
IF endtime > rs("endtime") AND flag = TRUE then
response.write "You can't register two hours at the same time"
END IF
rs.movenext
wend
Where
startime and endtime = The time got from the Form
and rs("starttime") and rs("endtime") are the time got from the DB
Well.. can I anyone help me find a solution ??
Comments
Break it down into small parts.
[code]
Use this somewhere in the Asp page...
you have to decide what's appropriate.
<%
If GlobalBooleanResult = -1 then
Response.Write("<script>window.alert('Overlapping time blocks!')")
End If%>
'I assume you have a button for submitting or something like that
'doesn't matter, you just need to handle an event and run the allocateTimeBlock()
Sub Button1_click()
GlobalBooleanResult = AllocateTimeBlock(parms here)
End Sub
Function AllocateTimeBlock(params here) as integer
If CheckForConflict(params here) = true then
'-1 in this sample is an error for conflict
'doesn't matter what it is just make something up
'but 0 should be unknown error and 1 should be success
AllocateTimeBlock = -1
Exit Function
End If
If InsertTimeBlock(params here) = true then
AllocateTimeBlock = 1
Else
AllocateTimeBlock = 0
End If
End Function
Function CheckForConflict(params here) as boolean
'Pseudocode...
SELECT Count(*) as Conflicts
FROM tbl
WHERE date = date
AND (newStartTime BETWEEN starttime AND endtime
OR newEndTime BETWEEN starttime AND endtime)
If recordset("conflicts").value >= 1 then
CheckForConflict = True
Else
CheckForConflict = False
End if
End Function
Function InsertTimeBlock(params here) as Boolean
'Pseudocode
Insert Data
IF itWorked then
InsertTimeBlock = True
Else
InsertTimeBlock = False
End If
End Function[/code]
Hope this helps you get organized. It should be easier to write with a clearer vision of a solution.
-ray
:
: I'm making an script so that the employees can register the hours that they have worked. The script is like this, the employee selects on a dropdown, the project that he is working, the start time and the end time.
: For example, he selects "Project 1" from "8:00" to "10:00"
:
: Ok.. until here, it's fine..
:
: But, he can't after this, put something like
: "Project 2" from "9:00" to "9:30"
: got it ?
Got it. You may not wish to consider this, but here it is anyway --
As a professional that works on multiple projects at one time, I sometimes find it preferable to actually work on 2 projects at the same time. If I run up against a brick wall on project 1, I switch to project 2 for a few minutes and let the back of my mind deal with the problem. Then 5 minutes later I'm back on 1 with a solution. Makes reporting a nightmare, but it's something to think about (but probably only for a minute or two ;-))
----------------
Walt
: :
: : I'm making an script so that the employees can register the hours that they have worked. The script is like this, the employee selects on a dropdown, the project that he is working, the start time and the end time.
: : For example, he selects "Project 1" from "8:00" to "10:00"
: :
: : Ok.. until here, it's fine..
: :
: : But, he can't after this, put something like
: : "Project 2" from "9:00" to "9:30"
: : got it ?
:
: Got it. You may not wish to consider this, but here it is anyway --
:
: As a professional that works on multiple projects at one time, I sometimes find it preferable to actually work on 2 projects at the same time. If I run up against a brick wall on project 1, I switch to project 2 for a few minutes and let the back of my mind deal with the problem. Then 5 minutes later I'm back on 1 with a solution. Makes reporting a nightmare, but it's something to think about (but probably only for a minute or two ;-))
:
: ----------------
: Walt
:
It wasn't stated, but often this type of app is somehow piped into the billing system and used to bill for hours in a professional organization (Law Firm, Consulting Firm, etc). If you are switching back and forth, you need to figure out exactly how much time for A and how much for B. If you take all the time for B sum it up and stick it at the end of the time slot for A that's fine. In such a situation, you could be liable for fraud if the employees double bill. So having some code implement a business rule would be a good thing.
-Ray
: : :
: : : I'm making an script so that the employees can register the hours that they have worked. The script is like this, the employee selects on a dropdown, the project that he is working, the start time and the end time.
: : : For example, he selects "Project 1" from "8:00" to "10:00"
: : :
: : : Ok.. until here, it's fine..
: : :
: : : But, he can't after this, put something like
: : : "Project 2" from "9:00" to "9:30"
: : : got it ?
: :
: : Got it. You may not wish to consider this, but here it is anyway --
: :
: : As a professional that works on multiple projects at one time, I sometimes find it preferable to actually work on 2 projects at the same time. If I run up against a brick wall on project 1, I switch to project 2 for a few minutes and let the back of my mind deal with the problem. Then 5 minutes later I'm back on 1 with a solution. Makes reporting a nightmare, but it's something to think about (but probably only for a minute or two ;-))
: :
: : ----------------
: : Walt
: :
: It wasn't stated, but often this type of app is somehow piped into the billing system and used to bill for hours in a professional organization (Law Firm, Consulting Firm, etc). If you are switching back and forth, you need to figure out exactly how much time for A and how much for B. If you take all the time for B sum it up and stick it at the end of the time slot for A that's fine. In such a situation, you could be liable for fraud if the employees double bill. So having some code implement a business rule would be a good thing.
:
: -Ray
:
Yes, this is to not have frauds, because our employees are paid by hours worked. So, if he is working on project 1 and stopped, so he should go and register hours the time that he worked. If he worked 5 minutes on project 2 , he must register this five minutes. Like, if he was working on projcet 1 from 8h to 10 ,but he stopped at 9h05 , so he should go and register project1 from 8h to 9h, and then for example from 9h35 to 10h, and if in this interval worked from 9h20 to 9h30 on project 2 , he must register this too..
So, that's the reason that I need to make this verification...
Function CheckForConflict(params here) as boolean
'Pseudocode...
SELECT Count(*) as Conflicts
FROM tbl
WHERE date = date
AND (newStartTime BETWEEN starttime AND endtime
OR newEndTime BETWEEN starttime AND endtime)
If recordset("conflicts").value >= 1 then
CheckForConflict = True
Else
CheckForConflict = False
End if
End Function
Putting only this part of the code, should it work ?
: [b][red]This message was edited by raymcd at 2003-6-26 13:5:6[/red][/b][hr]
: Break it down into small parts.
:
: [code]
: Use this somewhere in the Asp page...
: you have to decide what's appropriate.
: <%
: If GlobalBooleanResult = -1 then
: Response.Write("<script>window.alert('Overlapping time blocks!')")
: End If%>
:
: 'I assume you have a button for submitting or something like that
: 'doesn't matter, you just need to handle an event and run the allocateTimeBlock()
:
: Sub Button1_click()
: GlobalBooleanResult = AllocateTimeBlock(parms here)
: End Sub
:
: Function AllocateTimeBlock(params here) as integer
: If CheckForConflict(params here) = true then
: '-1 in this sample is an error for conflict
: 'doesn't matter what it is just make something up
: 'but 0 should be unknown error and 1 should be success
: AllocateTimeBlock = -1
: Exit Function
: End If
: If InsertTimeBlock(params here) = true then
: AllocateTimeBlock = 1
: Else
: AllocateTimeBlock = 0
: End If
: End Function
:
: Function CheckForConflict(params here) as boolean
: 'Pseudocode...
: SELECT Count(*) as Conflicts
: FROM tbl
: WHERE date = date
: AND (newStartTime BETWEEN starttime AND endtime
: OR newEndTime BETWEEN starttime AND endtime)
:
: If recordset("conflicts").value >= 1 then
: CheckForConflict = True
: Else
: CheckForConflict = False
: End if
: End Function
:
: Function InsertTimeBlock(params here) as Boolean
: 'Pseudocode
: Insert Data
: IF itWorked then
: InsertTimeBlock = True
: Else
: InsertTimeBlock = False
: End If
: End Function[/code]
:
: Hope this helps you get organized. It should be easier to write with a clearer vision of a solution.
:
: -ray
:
[red]As I stated
: : : Makes reporting a nightmare, but it's something to think about (but probably only for a minute or two ;-))[/red]
: : :
: : It wasn't stated, but often this type of app is somehow piped into the billing system and used to bill for hours in a professional organization (Law Firm, Consulting Firm, etc). If you are switching back and forth, you need to figure out exactly how much time for A and how much for B. If you take all the time for B sum it up and stick it at the end of the time slot for A that's fine. In such a situation, you could be liable for fraud if the employees double bill. So having some code implement a business rule would be a good thing.
: :
: : -Ray
[blue]Yeah, I know...[/blue]
:
: Yes, this is to not have frauds, because our employees are paid by hours worked. So, if he is working on project 1 and stopped, so he should go and register hours the time that he worked. If he worked 5 minutes on project 2 , he must register this five minutes. Like, if he was working on projcet 1 from 8h to 10 ,but he stopped at 9h05 , so he should go and register project1 from 8h to 9h, and then for example from 9h35 to 10h, and if in this interval worked from 9h20 to 9h30 on project 2 , he must register this too..
:
: So, that's the reason that I need to make this verification...
[blue]You might want to consider a bit pattern representing intervals of time. 64 bits (8 bytes) could designate 16 hours in 15 minute intervals. It would be easy to test whether a bit is already set based on the time that was just entered.
[/blue]
----------------
Walt
-ray
: So , the "key" is here , isn't ?
:
: Function CheckForConflict(params here) as boolean
: 'Pseudocode...
: SELECT Count(*) as Conflicts
: FROM tbl
: WHERE date = date
: AND (newStartTime BETWEEN starttime AND endtime
: OR newEndTime BETWEEN starttime AND endtime)
:
: If recordset("conflicts").value >= 1 then
: CheckForConflict = True
: Else
: CheckForConflict = False
: End if
: End Function
:
:
: Putting only this part of the code, should it work ?
:
:
:
:
: : [b][red]This message was edited by raymcd at 2003-6-26 13:5:6[/red][/b][hr]
: : Break it down into small parts.
: :
: : [code]
: : Use this somewhere in the Asp page...
: : you have to decide what's appropriate.
: : <%
: : If GlobalBooleanResult = -1 then
: : Response.Write("<script>window.alert('Overlapping time blocks!')")
: : End If%>
: :
: : 'I assume you have a button for submitting or something like that
: : 'doesn't matter, you just need to handle an event and run the allocateTimeBlock()
: :
: : Sub Button1_click()
: : GlobalBooleanResult = AllocateTimeBlock(parms here)
: : End Sub
: :
: : Function AllocateTimeBlock(params here) as integer
: : If CheckForConflict(params here) = true then
: : '-1 in this sample is an error for conflict
: : 'doesn't matter what it is just make something up
: : 'but 0 should be unknown error and 1 should be success
: : AllocateTimeBlock = -1
: : Exit Function
: : End If
: : If InsertTimeBlock(params here) = true then
: : AllocateTimeBlock = 1
: : Else
: : AllocateTimeBlock = 0
: : End If
: : End Function
: :
: : Function CheckForConflict(params here) as boolean
: : 'Pseudocode...
: : SELECT Count(*) as Conflicts
: : FROM tbl
: : WHERE date = date
: : AND (newStartTime BETWEEN starttime AND endtime
: : OR newEndTime BETWEEN starttime AND endtime)
: :
: : If recordset("conflicts").value >= 1 then
: : CheckForConflict = True
: : Else
: : CheckForConflict = False
: : End if
: : End Function
: :
: : Function InsertTimeBlock(params here) as Boolean
: : 'Pseudocode
: : Insert Data
: : IF itWorked then
: : InsertTimeBlock = True
: : Else
: : InsertTimeBlock = False
: : End If
: : End Function[/code]
: :
: : Hope this helps you get organized. It should be easier to write with a clearer vision of a solution.
: :
: : -ray
: :
:
: