Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

vb6 - Detecting Conflict in Day vb 6.0 and ms access

I have these records on my Day Table name tblday

  1. M
  2. T
  3. W
  4. TH
  5. F
  6. S
  7. MW
  8. TTH
  9. WF

Let say if I have this existing schedule:

  • ScheduleID = 10001
  • StartTime = 8:30 AM
  • EndTime = 1:00 PM
  • Day = M
  • Room = AVR
  • Course = BSN

Then If I add this new entry

  • ScheduleID = 10002
  • StartTime = 9:00 AM
  • EndTime = 10:00 AM
  • Day = MW
  • Room = AVR
  • Course = BSN

This should prompt a conflict in schedule because there is already a schedule for monday, then the new entry shouldn't be added. : )

Note: MW means 'Monday' AND 'Wednesday', I used this if they have both the same schedule. Because it would become redundant if add a new schedule for monday and add another for thursday with the same day, time, room and course. Also the same as TTH and MWF I can only detect conflict if it is not a combination of both Days (e.g MTH, TF, ...) I really spend a lot of time regarding this issue. Please I really need your help : (

Heres the code:

Function RoomInUse() As Boolean<br><br>
    Dim room As String<br>
    Dim day As String<br>
    Dim starttime As Date<br>
    Dim endtime As Date<br>
    Dim mond As String<br>
    Set rs = New ADODB.Recordset<br>
    With rs<br>
         mond = "select * from tblsched where room Like '" & room & "%' and day like '" & room & "' and (starttime <= #" & starttime & "# And " & _<br>
        "endtime >= #" & starttime & "#) Or (#" & starttime & "#" & _<br>
        "<= starttime And endtime < #" & endtime & "#) Or (#" & _<br>
       starttime & "# <= sarttime And starttime < #" & endtime & "#)) " '"<br>
         .Open mond, con, 3, 3<br>

    End With
    If rs.RecordCount >= 1 Then
        RoomInUse = True
    Else
        RoomInUse = False
    End If
End Function
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...