473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

tricky TimeSpan editing

I have a "Timesheet" application I am building for my company.

The way I have the sql tables setup, is each day has a unique record
for a specific user, then there is a TimeEntry table, that has multiple
TimeEntries for one day.

The TimeEntries for a specific day are like so:

7:00AM - 11:00AM : Regular Hours
11:00AM - 12:00PM : Lunch
12:00PM - 5:00PM : Regular Hours

now, when someone edits the lunch time entry and changes it to
11:30AM-12:00PM, I have some code that goes through the other
timeentries for that day and changes their startTime and EndTime to
coincide with the change to the "Lunch" entry, therefore there are no
gaps between time entries. this has turned into a little bit of a
nightmare because I currently have 7 if-elseif statements that does the
logical checking if a timeentry overlaps, and if the others need to be
changed. could there be an easier way to complete this logic without
having a number of if-elseif statements...here is my method that takes
care of changing other time entries:

/// <summary>
/// This checks overlap of times of all other TimeEntries for this
day in the database
/// if a TimeEntry overlaps ts/te, the TimeEntry is changed and saved
back to the database
/// </summary>
/// <param name="ts">TimeStart of the new TimeEntry</param>
/// <param name="te">TimeEnd of the new TimeEntry</param>
private void CheckOverlap(DateTime ts, DateTime te) {
DataSet dsTimeEntryByDay = this.GetTimeEntryByDay(DayID);
TimeSpan workingTime = te - ts;
int changed = 0;
foreach (DataRow dr in dsTimeEntryByDay.Tables["TimeEntry"].Rows) {
if (TimeEntryID != (int)dr["TimeEntryID"]) {
DateTime newTS = new DateTime();
DateTime newTE = new DateTime();
DateTime cTS = Convert.ToDateTime(dr["TimeStart"]);
DateTime cTE = Convert.ToDateTime(dr["TimeEnd"]);
changed = 0;

if (cTS < ts && cTE > ts) {
// If time is before changed time, and cTE overlaps ts
newTE = ts;
newTS = cTS;
changed = 1;
}
else if (cTE > te && cTS < te) {
// If time is after changed time, and cTS overlaps te
newTS = te;
newTE = cTE;
changed = 1;
}
else if (cTS < ts && cTE < ts) {
newTS = cTS;
newTE = ts;
changed = 1;
}

// Problem here, if you change the first entry, it changes the correct
one, and all subsequent entries
// because they all fit the criteria
else if (cTE > te && cTS > te && cTS < newTE) {
newTS = te;
newTE = cTE;
changed = 1;
}

if (changed == 1) {
this.UpdateTimeEntry((int)dr["TimeEntryID"], (int)dr["DayID"],
newTS, newTE, (int)dr["EntryTypeID"]);
}
}
}
}

Nov 17 '05 #1
0 870

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
3
by: Ivan A. | last post by:
Hi! Why I can't serialize TimeSpan structure with XmlSerializer? This is what I do: using System; using System.IO; using System.Xml; using System.Xml.Serialization;
7
by: DKode | last post by:
I have a "Timesheet" application I am building for my company. The way I have the sql tables setup, is each day has a unique record for a specific user, then there is a TimeEntry table, that has...
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
10
by: Charles Law | last post by:
If I display a TimeSpan I get something like 00:05:17.6217891 when what I would like to see is 00:05:18 Is there an easy way to get this output? Try as I might I just can't find it.
2
by: ucasesoftware | last post by:
i translate a C# funtion to VB.NET and i have this : Shared Function isAllDay(ByVal ap As Appointment) As Boolean Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap.DateEnd.TimeOfDay =...
2
by: Dennis D. | last post by:
Hello: I want to subtract a timespan from the selectionrange.start of a month calendar. The selectionrange.start of a month calendar is a date, and it is possible to subtract a timespan from a...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.