|
-
Feb 27th, 2010, 02:21 AM
#1
Thread Starter
Junior Member
detecting the 30 minutes interval in time scheduling
Hi! I have a problem in detecting the 30 minutes interval in time scheduling like for example i have a combobox(starting_time) and combobox2(endtime) and I select there 9:30-10:00 it has 30 minutes I want to show a message box that I should be 1 hour .Can you help me? Thanks in advance ^^
-
Feb 27th, 2010, 03:25 AM
#2
Re: detecting the 30 minutes interval in time scheduling
DateTimes can be added subtracted and compared:
vb.net Code:
Dim HalfAnHour As TimeSpan = TimeSpan.FromMinutes(30) Dim d1 As DateTime = DateTime.Parse("12:30") Dim d2 As DateTime = DateTime.Parse("12:26") Dim d3 As DateTime = DateTime.Parse("11:59") If d2 - d1 < HalfAnHour Then MsgBox("Less than 30 mins") End If If d2 - d3 > HalfAnHour Then MsgBox("More than 30 mins") ' Never called End If
-
Feb 27th, 2010, 04:25 AM
#3
Thread Starter
Junior Member
Re: detecting the 30 minutes interval in time scheduling
But how can i insert it there the combo box? the name of my combo box is starting_time and end_time? Thanks!
-
Feb 27th, 2010, 04:58 AM
#4
Re: detecting the 30 minutes interval in time scheduling
Put combobox1 and combobox2 on a form
vb.net Code:
' Put combobox1 and combobox2 on a form Public Class Form1 Dim StartTime As DateTime Dim EndTime As DateTime Dim halfanhour As TimeSpan = TimeSpan.FromMinutes(30) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim FiveMins = TimeSpan.FromMinutes(5) Dim t As DateTime = DateTime.Parse("0:00") For x = 0 To 47 ComboBox1.Items.Add(String.Format("{0:hh:mm}", t)) ComboBox2.Items.Add(String.Format("{0:hh:mm}", t)) t += FiveMins Next End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged StartTime = DateTime.Parse(ComboBox1.Items(ComboBox1.SelectedIndex).ToString) End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged EndTime = DateTime.Parse(ComboBox2.Items(ComboBox2.SelectedIndex).ToString) Dim diff As TimeSpan = EndTime - StartTime Dim msg As String msg = String.Format("Start time:{0:hh:mm}{1}End time:{2:hh:mm}{1}Difference:{3} minutes", _ New Object() {StartTime, Environment.NewLine, EndTime, diff.Minutes}) MsgBox(msg) End Sub End Class
-
Feb 27th, 2010, 05:19 AM
#5
Thread Starter
Junior Member
Re: detecting the 30 minutes interval in time scheduling
Thank you very much. I have 1 more problem on how to detect a conflict schedule i have this attribute:
* ScheduleID = 10002
* StartTime = 9:00 AM
* EndTime = 10:00 AM
* Day = MTH
* Room = AVR
* Course = BSN
I'm using MSSQL Server 2008. Can you help me also in this? because this is my last problem so that my system finish.. Thanks
-
Feb 27th, 2010, 05:23 AM
#6
Re: detecting the 30 minutes interval in time scheduling
what conflict schedule? what attribute? where? conflict with what?
-
Feb 27th, 2010, 06:26 AM
#7
Thread Starter
Junior Member
Re: detecting the 30 minutes interval in time scheduling
MS SQL2008
I have a time table day(nchar),course(nchar),room(nchar),starting_time(time),end_time(time)
I add an Entry:
day=WF
course=BSN
room=AVR
starting_time=7:00am
end_time=8:00am
VS2008
Now if inserted
day=WF
course=BSN
room=AVR
starting_time=7:30am
end_time=8:30am
it will show a msgbox conflict and it will not insert in the database but if not conflict then it will save on the database
-
Feb 27th, 2010, 07:17 AM
#8
Re: detecting the 30 minutes interval in time scheduling
This will require quite a bit of coding, by the way.
Let's assume that our New (N) time interval has its start (Ns) and end (Ne), and accordingly you have an Existing (E) time interval that has its start (Es) and end (Ee). Then you will have to check the following conditions before evaluating the result:
≤ - means less than or equal
≥ - means greater than or equal
((Ne ≥ Es) AND (Ne ≤ Ee))
OR
((Ns ≤ Es) AND (Ne ≥ Ee))
OR
((Ns ≤ Es) AND (Ne ≥ Es))
OR
((Ns ≥ Es) AND (Ns ≤ Ee))
Well, I hope that logic didn't fail me this time. It's even possible that this condition can be simplified, but my head aches to go through this again.
You will have to query all Starting_time and end_time fields from your table and perform the abovementioned checks with each pair before you can tell if there are any conflicts. Alternatively you can construct an SQL query with these conditions and check if it returns any records. The number of records returned will be the number of conflicts detected.
Last edited by cicatrix; Feb 27th, 2010 at 07:25 AM.
-
Feb 27th, 2010, 08:35 AM
#9
Thread Starter
Junior Member
Re: detecting the 30 minutes interval in time scheduling
Here's my code:
Dim con As New SqlClient.SqlConnection("Data source=NINOPADAMA;initial catalog=classScheduling;Integrated Security=True")
Dim cmd As New SqlCommand()
cmd.Connection = con
Dim RDR As SqlDataReader
con.Open()
cmd.CommandText = "Select * from timeload where (('" & ComboBox1.Text & "' Between stime And etime) Or ('" & ComboBox2.Text & "' Between stime And etime))"
RDR = cmd.ExecuteReader
If RDR.HasRows = True Then
MsgBox("Conflict")
Else
MsgBox("Success")
End If
In my table stime(time),etime(time)
My school starts 7:00AM to 9:00PM. the code for the conflict works if i had an input of any time from 7am-4pm but if i set it in any time from 5pm til 9pm it prompts me a msgbox saying success rather than an error mssge. Can you help me with this?
-
Feb 27th, 2010, 09:06 AM
#10
Re: detecting the 30 minutes interval in time scheduling
Here is the four possible variants of conflict:
Code:
A.
New: ***
----------------------------> Time axis
Existing: **********
B.
New: *************
----------------------------> Time axis
Existing: ****
C.
New: ********
----------------------------> Time axis
Existing: ********
D.
New: ********
----------------------------> Time axis
Existing: ********
Your SQL should just check all four conditions to be false.
-
Feb 27th, 2010, 09:20 AM
#11
Thread Starter
Junior Member
Re: detecting the 30 minutes interval in time scheduling
I'm not familiar with that code? Can you give another way? Thanks
-
Feb 27th, 2010, 09:26 AM
#12
Re: detecting the 30 minutes interval in time scheduling
It's not a code, it's a diagram.
-
Feb 27th, 2010, 03:41 PM
#13
Thread Starter
Junior Member
Re: detecting the 30 minutes interval in time scheduling
Can you modify my code? And add this attribute day,course,room
to become day,course,room,starting_time,end_time?
When I test my code its working ,the data type I used in starting_time and end_time is datetime but like I've said the conflict works if i had an input of any time from 7am-4pm but if i set it in any time from 5pm til 9pm it prompts me a msgbox saying success rather than an error mssge
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
|