.net - Check if Time Range intersects in C# -
.net - Check if Time Range intersects in C# -
this question has reply here:
algorithm observe overlapping periods 8 answersi developing simple enrollment scheme in c# , thinking if there straightforward way check if time range (from - to) of input session intersects time range in database.
the scenario follows:
i have table in database named tblsessionlist
stores different sessions per subject , want check each time user adds new session if particular room
occupied in particular time range. technically, want check if chosen time range not conflict sessions in tblsessionlist
.
tblsessionlist
| subject code | venue | room | date | | | | | | | | | | | crgov401 | gt tower | room 3d | thursday, june 19, 2014 | 8:00 |10:00 | | crgov401 | gt tower | room 59 | sunday, june 29, 2014 | 1:00 pm |3:00 pm | | gnbnk201 | main plaza | hr hall | monday, june 30, 2014 | 9:00 |11:00 | | gnbnk201 | main plaza | hr hall | monday, june 30, 2014 | 1:00 pm |3:00 |
i have tried doing following:
private void btnaddsession_click(object sender, eventargs e) { bool proceedcopy = true; datatable timeholder = new datatable(); sqldataadapter selecttime = new sqldataadapter("select [from],[to] tblsessionlist [venue] = @venue , [room] = @room", connection.conn); selecttime.selectcommand.parameters.addwithvalue("@venue", venue.text); selecttime.selectcommand.parameters.addwithvalue("@room", room.text); selecttime.fill(timeholder); for(int = 0; < timeholder.rows.count; i++) { if(timeholder[i][0].tostring() == from.text) //checks if 'from' of query same 'from' of new entry { messagebox.show("the room occupied on time range"); proceedcopy = false; break; } else if(timeholder[i][1].tostring() == to.text) //checks if 'to' of query same 'to' of new entry. { messagebox.show("the room occupied on time range"); proceedcopy = false; break; } } if(proceedcopy == true) //insert code insert new session database here }
this hard-coded checking , checks end points of time range, not time range itself. i'm thinking if there's function in c# utilize time instead of datetime.
note: every column in database varchar. apologies having dirty code first scheme ever.
any help much appreciated.
you can utilize interval tree search on database . interval tree store range (a,b) , builds bst using comparing between 2 intervals , decide whether comes left or right. search on interval tree can done in o(logn).
c# .net winforms algorithm visual-studio-2012
Comments
Post a Comment