|
-
May 10th, 2007, 03:34 AM
#1
Thread Starter
Member
[2005] Timespan 2 shifts.
Hi,
Im having some difficulty implementing 2 shifts.
For example. A person works from 8:00 - 16.00 on 10th of may
The next time a person enters a timespan from say 15.00 - 18.00 on the 10th of may , it should give an error. Because 15.00 - 16.00 he already worked.
It should also work with Crossdates if someone worked like 11th of may and also did a latenight shift on the 10th of may.
Does anyone know a thread that had the same problem cause ive searched the forum and not found any.
Is the Timespan.compare the answer to my problems?
-
May 10th, 2007, 03:51 AM
#2
Re: [2005] Timespan 2 shifts.
The TimeSpan is useless to you because it has no concept of when it started or when it finished. A TimeSpan could represent 3 minute and 47 seconds, but that could be from before Christ, last week, today or some time in the distant future. The TimeSpan doesn't know. Think of a TimeSpan like a piece of string. You can put it wherever you like and it's still the same length. It doesn't care where it starts or where it ends.
You need to keep two distinct DateTime objects for the start of a shift and the end. Only then can you compare two shifts to see if they overlap.
Given that this is OOP you should do it the OO way. Create a Shift class. Take a start time and an end time in the constructor. Provide a Duration property that returns the TimeSpan that is the difference between the two DateTimes. Provide a method to compare two shifts to see if they overlap. For that you check the start times to see which one was started first. You'd then check whether the first one also finished before or when the second one started.
-
May 10th, 2007, 04:07 AM
#3
Thread Starter
Member
Re: [2005] Timespan 2 shifts.
Well ive got no clue to do this the OO way.Im just a little familiar with it and writing something like this is i think a bit out of my league.
Are there no examples for this kind of problem , if you dont mind me asking.
Is there a way to check this with a simple loop instead of doing it the OO way ?
ps: Im a bit mind boggled after reading that
Last edited by IamMacro; May 10th, 2007 at 04:12 AM.
-
May 10th, 2007, 04:09 AM
#4
Re: [2005] Timespan 2 shifts.
I've already told you how to determine whether two shifts overlap:
you check the start times to see which one was started first. You'd then check whether the first one also finished before or when the second one started.
That holds true whether you're using creating a class to represent a shift or not.
-
May 10th, 2007, 04:47 AM
#5
Thread Starter
Member
Re: [2005] Timespan 2 shifts.
nm this one
appreciate your help
Last edited by IamMacro; May 10th, 2007 at 08:29 AM.
-
May 10th, 2007, 04:53 AM
#6
Re: [2005] Timespan 2 shifts.
As I have already said, twice, if you want to test whether two shifts overlap you first compare their start times to see which started first. You then compare the end time of the first with the start time of the second. If the first ends when or before the second starts then they do not overlap. So, start creating your DateTime objects and comparing them.
-
May 10th, 2007, 04:59 AM
#7
Thread Starter
Member
Re: [2005] Timespan 2 shifts.
Yeah Sorry , about that but i forgot to tell , my field
WorkdayStart is a datetime with "05/05/2007" 9:00 - "05/05/2007" 15:00
second row (is a different workday) "05/05/2007" 9:00 - "05/05/2007" 17:00
but i understand that the Datetime variable checks the entire Datetime.
So i think ill get it now.
thx jmcilhinney.
-
May 10th, 2007, 07:27 AM
#8
Thread Starter
Member
Re: [2005] Timespan 2 shifts.
dtewerk = datepicker.value.date "10-05-2007"
straankomst = "3:15"
insertCommand.Parameters("workdaystart").Value =
DateTime.Parse(dtewerk & straankomst, "DD/MM/YYYY HH:MM")
Im getting an InvalidCast Exception , what am i doing wrong ?
-
May 10th, 2007, 07:50 AM
#9
Re: [2005] Timespan 2 shifts.
So you are adding the data to a DB? Would it not be better having just 1 column (of DateTime type) and then adding the value from the DateTime Picker to that. It would store the date and time anyway?
vb Code:
Dim startTime As DateTime = Me.DateTimePicker1.Value
MessageBox.Show(startTime.ToShortDateString)
MessageBox.Show(startTime.ToShortTimeString)
-
May 10th, 2007, 08:20 AM
#10
Thread Starter
Member
Re: [2005] Timespan 2 shifts.
Users can enter a Workday on a later time.
So they work from 8:00 - 16:00 but they filled it in the next day.
So im using Comboboxes filled with 1 2 3 4 - 23 , and 0 15 30 45 for minutes to let them pick a time
Code:
dim _dtewerk as string
_dtework = Format(Datetimepicker1.Value, "dd/MM/yyyy")
_strarrival = cmbHours.text & " " & cmbminutes.text
Dim test As String = _dtewerk & " " & _strarrival
insertCommand.Parameters("start").Value = test
this works but is far from perfect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|