Results 1 to 13 of 13

Thread: detecting the 30 minutes interval in time scheduling

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    19

    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 ^^

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: detecting the 30 minutes interval in time scheduling

    DateTimes can be added subtracted and compared:

    vb.net Code:
    1. Dim HalfAnHour As TimeSpan = TimeSpan.FromMinutes(30)
    2.         Dim d1 As DateTime = DateTime.Parse("12:30")
    3.         Dim d2 As DateTime = DateTime.Parse("12:26")
    4.         Dim d3 As DateTime = DateTime.Parse("11:59")
    5.  
    6.  
    7.         If d2 - d1 < HalfAnHour Then
    8.             MsgBox("Less than 30 mins")
    9.         End If
    10.  
    11.         If d2 - d3 > HalfAnHour Then
    12.             MsgBox("More than 30 mins") ' Never called
    13.         End If

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    19

    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!

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: detecting the 30 minutes interval in time scheduling

    Put combobox1 and combobox2 on a form

    vb.net Code:
    1. ' Put combobox1  and combobox2 on a form
    2. Public Class Form1
    3.  
    4.     Dim StartTime As DateTime
    5.     Dim EndTime As DateTime
    6.     Dim halfanhour As TimeSpan = TimeSpan.FromMinutes(30)
    7.  
    8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    9.         Dim FiveMins = TimeSpan.FromMinutes(5)
    10.         Dim t As DateTime = DateTime.Parse("0:00")
    11.         For x = 0 To 47
    12.             ComboBox1.Items.Add(String.Format("{0:hh:mm}", t))
    13.             ComboBox2.Items.Add(String.Format("{0:hh:mm}", t))
    14.             t += FiveMins
    15.         Next
    16.     End Sub
    17.  
    18.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    19.         StartTime = DateTime.Parse(ComboBox1.Items(ComboBox1.SelectedIndex).ToString)
    20.     End Sub
    21.  
    22.     Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
    23.         EndTime = DateTime.Parse(ComboBox2.Items(ComboBox2.SelectedIndex).ToString)
    24.         Dim diff As TimeSpan = EndTime - StartTime
    25.         Dim msg As String
    26.         msg = String.Format("Start time:{0:hh:mm}{1}End time:{2:hh:mm}{1}Difference:{3} minutes", _
    27.                              New Object() {StartTime, Environment.NewLine, EndTime, diff.Minutes})
    28.  
    29.         MsgBox(msg)
    30.     End Sub
    31.  
    32. End Class

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    19

    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

  6. #6

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    19

    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

  8. #8
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    19

    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?

  10. #10
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    19

    Re: detecting the 30 minutes interval in time scheduling

    I'm not familiar with that code? Can you give another way? Thanks

  12. #12

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    19

    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
  •  



Click Here to Expand Forum to Full Width