Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.46 KB | None | 0 0
  1. Protected Sub btnCheck_Click(sender As Object, e As System.EventArgs) Handles btnCheck.Click
  2.  
  3. ' Variables
  4. Dim arrRunning(0)
  5. ReDim arrRemoveDates(0)
  6. ReDim arrFinalDates(0)
  7. Dim arrTRID
  8. Dim arrVDClosed(0)
  9. Dim arrDOW(7)
  10. Dim oGlobals As New oGlobals
  11. Dim arrConflict(0)
  12. Dim bBlock As Boolean = False
  13. Dim bConflict As Boolean = False
  14. Dim bConflictExists As Boolean = False
  15. Dim bConflictOverride As Boolean = False
  16. Dim bRace As Boolean = False
  17. Dim bAdHoc As Boolean = False
  18. Dim bMeeting As Boolean = False
  19. Dim bOverride As Boolean = False
  20. Dim bRFOverride As Boolean = False
  21. Dim bParticipentAdded As Boolean = False
  22. Dim bRepeat As Boolean = False
  23. Dim bSiteClosed As Boolean = False
  24. Dim bSameEvent As Boolean = False
  25. Dim dstData As DataSet
  26. Dim dstDataClone As New DataSet
  27. Dim dstTable As DataTable
  28. Dim dstRow As DataRow
  29. Dim dstCol As DataColumn
  30. Dim dstRForm As New DataSet
  31. Dim dtmDate As DateTime
  32. Dim dtmEndTime As Date
  33. Dim dtmStartTime As Date
  34. Dim dtmSQLCheck As Date
  35. Dim dtmSQLAdjust As Date
  36. Dim dtmStart As Date
  37. Dim dtmEnd As Date
  38. Dim dtmVDDate As Date
  39. Dim dMinute As Double
  40. Dim dDuration As Double = 0
  41. Dim intTR_NoOfKarts As Integer = 0
  42. Dim intRF_MaxDrivers As Integer = 0
  43. Dim intRF_MaxDrivers_Alt As Integer = 0
  44. Dim intSQLDOW As Integer = 0
  45. Dim intACnt As Integer = 0
  46. Dim intCnt As Integer = 0
  47. Dim intCCnt As Integer = 0
  48. Dim intConCount As Integer = 0
  49. Dim intDaysClosed As Integer = 0
  50. Dim intDayOfWeek As Integer = 0
  51. Dim intErr As Integer = 0
  52. Dim intId As Integer = 0
  53. Dim intNoOfApps As Integer = 0
  54. Dim intNoOfAppsToRemove As Integer = 0
  55. Dim intNoOfDriver As Integer = 0
  56. Dim sAltSQL As String = "(AD_ATID IN (7)) AND "
  57. Dim sTempNotice As String = ""
  58. Dim sLabel As String = "people"
  59. Dim sDtmDisplay As String = ""
  60. Dim sTempInternalNotice As String = ""
  61. Dim sId As String = ""
  62. Dim dstAdHoc As New DataSet
  63. Dim sAdHocSQL As String = ""
  64. Dim sTempDateString As String = ""
  65. Dim sTimeConflict As String = ""
  66. Dim intInCCnt As Integer = 0
  67. Dim bExists As Boolean = False
  68. Dim dtmCheck As DateTime
  69. Dim dtmCheckII As DateTime
  70. Dim intACount As Integer = 0
  71. Dim bIgnore As Boolean = False
  72. Dim bFinished As Boolean = False
  73. Dim dtmRunning As Date
  74. Dim dtmFStart As Date
  75. Dim dInt As Double
  76. Dim dtmEndRun As DateTime
  77.  
  78.  
  79. sqlConn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("sqlConn"))
  80.  
  81. Using sqlConn
  82.  
  83. ' Collect the connection using the protected method
  84. sqlConn = oGlobals.returnSQLConn(sqlConn)
  85.  
  86. ' Setup default parameters
  87. Select Case ddlAT_ATID.SelectedValue
  88. Case -4 ' Block Booking
  89. bAdHoc = False
  90. bBlock = True
  91. bMeeting = False
  92. bRace = False
  93. Case -3 ' Meeting
  94. bAdHoc = False
  95. bBlock = False
  96. bMeeting = True
  97. bRace = False
  98. sLabel = "People"
  99. Case -2 ' Adhoc
  100. bAdHoc = True
  101. bBlock = False
  102. bMeeting = False
  103. bRace = False
  104. sLabel = "Participants"
  105. Case -1 ' Race
  106. bAdHoc = False
  107. bBlock = False
  108. bMeeting = False
  109. bRace = True
  110. sLabel = "drivers"
  111. End Select
  112.  
  113. If chkAP_Repeat.Checked Then bRepeat = True
  114.  
  115. ' Validate
  116. If returnValid(bAdHoc, bRace, bRepeat, sLabel, bMeeting, bBlock) Then
  117.  
  118. Dim intRF_RFID_Chk As Integer = 0
  119. If ddlRF_RFID.SelectedValue & "" <> "" Then intRF_RFID_Chk = ddlRF_RFID.SelectedValue
  120. If Not fnc_ScheduledFormat(intRF_RFID_Chk) Then
  121.  
  122. ' Sortout the number of drivers
  123. intNoOfDriver = Session("AP_AD_Drivers") + Session("AP_ALT_Drivers")
  124.  
  125. ' Check availability
  126. lbl_Message.Text = ""
  127.  
  128. ' Collect the connection using the protected method
  129. sqlConn = oGlobals.returnSQLConn(sqlConn)
  130.  
  131. ' Collect race format information
  132. If (Not bAdHoc) And (Not bMeeting) And (Not bBlock) Then dstRForm = returnProducts(ddlRF_RFID.SelectedValue)
  133.  
  134. If ddlAT_ATID.SelectedValue = -3 Then
  135. sAltSQL = "(AD_ATID IN (12)) AND "
  136. Else
  137. sAltSQL = "(AD_ATID IN (6,8,10,11,13)) AND "
  138. End If
  139.  
  140. ' Collect any linked Id's - will always return at least one (the selected activity center)
  141. arrTRID = returnACLinks(ddlTR_TRID.SelectedValue)
  142. For intCnt = 0 To UBound(arrTRID, 1)
  143. If intCnt < UBound(arrTRID, 1) Then
  144. sId = sId & arrTRID(intCnt) & ","
  145. Else
  146. sId = sId & arrTRID(intCnt)
  147. End If
  148. Next
  149. ' remove the final comma if needed
  150. If UBound(arrTRID, 1) > 1 Then sId = Mid(sId, 1, (Len(sId) - 1))
  151.  
  152. ' Depending on the repeat option
  153. ' We have to check different options
  154. Select Case bRepeat
  155. Case True
  156.  
  157. ' Setup the date parameter
  158. Dim intDaysToAdd As Integer = 0
  159. dtmSQLCheck = FormatDateTime(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString)
  160.  
  161. ' Sort out the day of the week filter if it's a weekly
  162. ' or hourly type of repeat, if it's a monthly repeat
  163. ' then setup the end date based on the number of months
  164. Select Case ddlAP_Frequency.SelectedValue
  165. Case 0, 2 'Hourly/Weekly
  166. dtmSQLAdjust = calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString
  167.  
  168. ' Set/all to false
  169. For intCnt = 1 To 7
  170. arrDOW(intCnt) = False
  171. Next
  172.  
  173. ' Update the selected days
  174. If chkSun.Checked Then arrDOW(1) = True
  175. If chkMon.Checked Then arrDOW(2) = True
  176. If chkTue.Checked Then arrDOW(3) = True
  177. If chkWed.Checked Then arrDOW(4) = True
  178. If chkThu.Checked Then arrDOW(5) = True
  179. If chkFri.Checked Then arrDOW(6) = True
  180. If chkSat.Checked Then arrDOW(7) = True
  181.  
  182. Case 1 'Daily
  183. dtmSQLAdjust = calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString
  184.  
  185. Case 3 ' Monthly
  186. dtmSQLAdjust = DateAdd(DateInterval.Month, CInt(ddlRF_Months.SelectedValue), CDate(dtmSQLCheck))
  187.  
  188. Case 4 ' Ad Hoc
  189. If Not IsNothing(Session("dstAdHocDate")) Then
  190. dstAdHoc = Session("dstAdHocDate")
  191. For intCnt = 0 To dstAdHoc.Tables(0).Rows.Count - 1
  192. dtmDate = FormatDateTime(dstAdHoc.Tables(0).Rows(intCnt).Item("AH_dtmEvent"), DateFormat.ShortDate)
  193. sTempDateString = Right(dtmDate, 4) & Mid(dtmDate, 4, 2) & Left(dtmDate, 2)
  194. sAdHocSQL = sAdHocSQL & "(AP_dtmAppointmentStart = '" & sTempDateString & "')"
  195. If intCnt <> dstAdHoc.Tables(0).Rows.Count - 1 Then sAdHocSQL = sAdHocSQL & " OR "
  196. Next
  197. End If
  198.  
  199. End Select
  200.  
  201. calAP_dtmAppointmentEnd.SelectedDate = dtmSQLAdjust
  202. sSQL = "SELECT DISTINCT AP_ACID, RF_RFID, RF_Duration, RF_Name, RF_MaxDrivers, RF_MinAge, RF_MaxAge, AC_Name, AS_Name, AP_APID, AP_dtmAppointmentStart, CONVERT(VARCHAR(8),AP_StartTime,108) AS AP_StartTime, AP_EndTime, RF_PTID, RF_TRID, " &
  203. "(RF_MaxDrivers - COALESCE((SELECT SUM(AD_NoParticipents) FROM tbl_AD_AppointmentDetails WHERE AD_APID = AP_APID AND AD_ASID <= 280 AND AD_CLID > -1), 0) - @AP_NoOfDrivers) AS AP_Avail, AP_NoParticipents, RF_ETID, TR_MaxKarts, AD_NoParticipents " &
  204. "FROM tbl_AP_Appointment LEFT OUTER JOIN " &
  205. "tbl_AD_AppointmentDetails ON AP_APID = AD_APID LEFT OUTER JOIN " &
  206. "tbl_RF_RaceFormat ON AD_RFID = RF_RFID LEFT OUTER JOIN " &
  207. "tbl_TR_Track ON RF_TRID = TR_TRID LEFT OUTER JOIN " &
  208. "tbl_AS_AppointmentStatus ON AP_ASID = AS_ASID LEFT OUTER JOIN " &
  209. "tbl_AC_AppointmentClass ON AP_ACID = AC_ACID " &
  210. "WHERE (AP_dtmAppointmentStart >= @AP_dtmAppointmentStart) AND "
  211.  
  212. ' Add filter depending on type of repeat
  213. Dim dtmAP_Start As DateTime
  214. Select Case ddlAP_Frequency.SelectedValue
  215. Case 0, 2 ' Hourly/Weekly
  216. sSQL &= "("
  217. For intCnt = 1 To 7
  218. If arrDOW(intCnt) Then
  219. If intACnt > 0 Then sSQL &= " OR "
  220. sSQL &= "(DATEPART(Dw,AP_dtmAppointmentStart) = " & intCnt & ")"
  221. intACnt = intACnt + 1
  222. End If
  223. Next
  224.  
  225. If intACnt > 0 Then sSQL &= ") AND "
  226. intACnt = 0
  227. dtmAP_Start = calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString
  228. Case 1, 3
  229. dtmAP_Start = calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString
  230. Case 4
  231. sSQL &= "(" & sAdHocSQL & ") AND "
  232. dstAdHoc = Session("dstAdHocDate")
  233. dtmAP_Start = FormatDateTime(dstAdHoc.Tables(0).Rows(0).Item("AH_dtmEvent"), DateFormat.ShortDate)
  234. End Select
  235.  
  236. ' Add filter for race/meeting
  237. sSQL &= sAltSQL &
  238. "(AP_VEID = @AP_VEID) AND " &
  239. "(AD_TRID IN (" & sId & ")) AND " &
  240. "AP_ASID NOT IN (300,400,500,600) AND " &
  241. "AD_ASID NOT IN (300,400,500,600) AND " &
  242. "AD_Deleted = 0 AND " &
  243. "(AD_CLID > -1) AND " &
  244. "RF_NonSchedule = 0 " &
  245. "ORDER BY CONVERT(VARCHAR(8),AP_StartTime,108), RF_Name ASC"
  246.  
  247. ' SQL Parameters
  248. sqlCmd = New SqlCommand(sSQL, sqlConn)
  249. sqlCmd.Parameters.Add("@AP_NoOfDrivers", SqlDbType.Int, 4).Value = intNoOfDriver
  250. sqlCmd.Parameters.Add("@AP_dtmAppointmentStart", SqlDbType.DateTime, 8).Value = FormatDateTime(dtmAP_Start, DateFormat.ShortDate)
  251. sqlCmd.Parameters.Add("@AP_VEID", SqlDbType.Int, 4).Value = ddlVE_VEID.SelectedValue
  252. sqlAdap = New SqlDataAdapter(sqlCmd)
  253.  
  254. Case False
  255.  
  256. sSQL = "SELECT DISTINCT AP_ACID, RF_RFID, RF_Duration, RF_Name, RF_MaxDrivers, RF_MinAge, RF_MaxAge, AC_Name, AS_Name, AP_APID, AP_dtmAppointmentStart, CONVERT(VARCHAR(8),AP_StartTime,108) AS AP_StartTime, AP_EndTime, RF_PTID, RF_TRID, " &
  257. "(RF_MaxDrivers - COALESCE((SELECT SUM(AD_NoParticipents) FROM tbl_AD_AppointmentDetails WHERE AD_APID = AP_APID AND AD_ASID <= 280 AND AD_CLID > -1), 0) - @AP_NoOfDrivers) AS AP_Avail, AP_NoParticipents, RF_ETID, TR_MaxKarts, AD_NoParticipents " &
  258. "FROM tbl_AP_Appointment LEFT OUTER JOIN " &
  259. "tbl_AD_AppointmentDetails ON AP_APID = AD_APID LEFT OUTER JOIN " &
  260. "tbl_RF_RaceFormat ON AD_RFID = RF_RFID LEFT OUTER JOIN " &
  261. "tbl_TR_Track ON RF_TRID = TR_TRID LEFT OUTER JOIN " &
  262. "tbl_AS_AppointmentStatus ON AP_ASID = AS_ASID LEFT OUTER JOIN " &
  263. "tbl_AC_AppointmentClass ON AP_ACID = AC_ACID " &
  264. "WHERE (AP_dtmAppointmentStart = @AP_dtmAppointmentStart) AND "
  265.  
  266. ' Filter for modifying events
  267. If hidAP_APID.Value <> "" Then
  268. sSQL &= sAltSQL &
  269. " (AP_APID <> " & hidAP_APID.Value & ") AND "
  270. End If
  271.  
  272. ' Add filter for race/meeting
  273. sSQL &= sAltSQL &
  274. "(AP_VEID = @AP_VEID) AND " &
  275. "(AD_TRID IN (" & sId & ")) AND " &
  276. "AP_ASID NOT IN (300,400,500,600) AND " &
  277. "AD_ASID NOT IN (300,400,500,600) AND " &
  278. "AD_Deleted = 0 AND " &
  279. "(AD_CLID > -1) AND " &
  280. "RF_NonSchedule = 0 " &
  281. "ORDER BY CONVERT(VARCHAR(8),AP_StartTime,108), RF_Name ASC"
  282.  
  283. ' SQL Parameters
  284. sqlCmd = New SqlCommand(sSQL, sqlConn)
  285. sqlCmd.Parameters.Add("@AP_NoOfDrivers", SqlDbType.Int, 4).Value = intNoOfDriver
  286. sqlCmd.Parameters.Add("@AP_dtmAppointmentStart", SqlDbType.DateTime, 8).Value = calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString
  287. sqlCmd.Parameters.Add("@AP_VEID", SqlDbType.Int, 4).Value = ddlVE_VEID.SelectedValue
  288. sqlAdap = New SqlDataAdapter(sqlCmd)
  289.  
  290. End Select
  291.  
  292.  
  293. dstData = New DataSet
  294. sqlAdap.Fill(dstData, "AllTables")
  295. ReDim Preserve arrConflict(dstData.Tables("AllTables").Rows.Count)
  296. For intCnt = 0 To dstData.Tables("AllTables").Rows.Count - 1
  297. arrConflict(intCnt) = -1
  298. Next
  299.  
  300. ' Setup date/time and duration variables
  301. ' Remember to set the duration manually if it's an adhoc thing
  302. Dim intAFCnt As Integer = 0
  303. Dim intAFCCnt As Integer = 0
  304. If bAdHoc Or bMeeting Or bBlock Then
  305. dDuration = txt_AH_Duration.Text
  306. Else
  307. dDuration = oGlobals.returnDuration(ddlRF_RFID.SelectedValue, intNoOfDriver)
  308. End If
  309.  
  310. dtmStartTime = FormatDateTime(ddlAP_StartTime.SelectedValue, DateFormat.ShortTime)
  311. dtmEndTime = DateAdd(DateInterval.Minute, CDbl(dDuration), CDate(FormatDateTime(ddlAP_StartTime.SelectedValue, DateFormat.ShortTime)))
  312.  
  313. ' Establish the counts for potential entries
  314. ' Add an additional day on the Daily/Hourly basis to include the final day
  315. If bRepeat Then
  316. Select Case ddlAP_Frequency.SelectedValue
  317.  
  318. Case 0 ' Hourly
  319.  
  320. Dim intNoOfActualApps As Integer = 0
  321. intNoOfApps = DateDiff(DateInterval.DayOfYear, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString), CDate(calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString)) + 1
  322. dtmEndTime = ddlRF_EndTime.SelectedValue
  323. dtmFStart = FormatDateTime(dtmStartTime, DateFormat.ShortTime)
  324. ReDim arrRunning(0)
  325. intCnt = 0
  326. Do
  327. If intCnt = 0 Then
  328. dtmRunning = FormatDateTime(dtmStartTime, DateFormat.ShortTime)
  329. Else
  330. dInt = intCnt * dDuration
  331. dtmRunning = DateAdd(DateInterval.Minute, dInt, dtmFStart)
  332. End If
  333.  
  334. If FormatDateTime(dtmRunning, DateFormat.ShortTime) >= FormatDateTime(dtmEndTime, DateFormat.ShortTime) Then bFinished = True
  335.  
  336. If Not bFinished Then
  337. arrRunning(intCnt) = dtmRunning
  338. intCnt = intCnt + 1
  339. ReDim Preserve arrRunning(intCnt)
  340. End If
  341.  
  342. Loop Until bFinished
  343.  
  344. ' Are things open
  345. If intNoOfApps >= 1 Then
  346. arrVDClosed = returnSiteClosedStatus()
  347. If arrVDClosed(0) = -1 Then
  348. For intCnt = 0 To intNoOfApps
  349. ' Get the date
  350. dtmVDDate = DateAdd(DateInterval.DayOfYear, intCnt, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString))
  351. ' Get the day of the week
  352. intDayOfWeek = DatePart(DateInterval.Weekday, dtmVDDate)
  353. For intACnt = 1 To 7
  354. ' If the day of the week matches and that day has been
  355. ' Specified as a day to run, then check against closures
  356. If intDayOfWeek = intACnt Then
  357. If arrDOW(intACnt) Then
  358. intNoOfActualApps = intNoOfActualApps + 1
  359. For intCCnt = 0 To UBound(arrVDClosed, 1) - 1
  360. If DatePart(DateInterval.Weekday, dtmVDDate) = arrVDClosed(intCCnt) Then
  361. arrConflictDates(intNoOfAppsToRemove) = dtmVDDate
  362. intNoOfAppsToRemove = intNoOfAppsToRemove + 1
  363. ReDim Preserve arrConflictDates(intNoOfAppsToRemove)
  364. Else
  365. For intAFCCnt = 0 To UBound(arrRunning, 1) - 1
  366. arrFinalDates(intAFCnt) = FormatDateTime(dtmVDDate, DateFormat.ShortDate) & " " & arrRunning(intAFCCnt)
  367. intAFCnt = intAFCnt + 1
  368. ReDim Preserve arrFinalDates(intAFCnt)
  369. Next
  370. End If
  371. Next
  372. End If
  373. End If
  374. Next
  375. Next
  376. Else
  377. For intCnt = 0 To intNoOfApps
  378. ' Get the date
  379. dtmVDDate = DateAdd(DateInterval.DayOfYear, intCnt, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString))
  380. ' Get the day of the week
  381. intDayOfWeek = DatePart(DateInterval.Weekday, dtmVDDate)
  382. For intACnt = 1 To 7
  383. ' If the day of the week matches and that day has been
  384. ' Specified as a day to run
  385. If intDayOfWeek = intACnt Then
  386. If arrDOW(intACnt) Then
  387. intNoOfActualApps = intNoOfActualApps + 1
  388. arrFinalDates(intAFCnt) = FormatDateTime(dtmVDDate, DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  389. intAFCnt = intAFCnt + 1
  390. ReDim Preserve arrFinalDates(intAFCnt)
  391. End If
  392. End If
  393. Next
  394. Next
  395. End If
  396. End If
  397.  
  398. ' Update the final date array to include the timings
  399. ' Set the new totals up
  400. intDaysClosed = intNoOfAppsToRemove
  401. intNoOfApps = UBound(arrFinalDates, 1)
  402.  
  403. Case 2 ' Weekly
  404.  
  405. Dim intNoOfActualApps As Integer = 0
  406. intNoOfApps = DateDiff(DateInterval.DayOfYear, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString), CDate(calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString))
  407.  
  408. ' Collect the days the venue is closed
  409. ' Then remove those dates from the possible creations
  410. ' This applies to Hourly/Weekly repeats
  411. ' Add the dates to the conflict date array
  412. If intNoOfApps >= 1 Then
  413. arrVDClosed = returnSiteClosedStatus()
  414. If arrVDClosed(0) = -1 Then
  415. For intCnt = 0 To intNoOfApps
  416. ' Get the date
  417. dtmVDDate = DateAdd(DateInterval.DayOfYear, intCnt, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString))
  418. ' Get the day of the week
  419. intDayOfWeek = DatePart(DateInterval.Weekday, dtmVDDate)
  420. For intACnt = 1 To 7
  421. ' If the day of the week matches and that day has been
  422. ' Specified as a day to run, then check against closures
  423. If intDayOfWeek = intACnt Then
  424. If arrDOW(intACnt) Then
  425. intNoOfActualApps = intNoOfActualApps + 1
  426. For intCCnt = 0 To UBound(arrVDClosed, 1) - 1
  427. If DatePart(DateInterval.Weekday, dtmVDDate) = arrVDClosed(intCCnt) Then
  428. arrConflictDates(intNoOfAppsToRemove) = dtmVDDate
  429. intNoOfAppsToRemove = intNoOfAppsToRemove + 1
  430. ReDim Preserve arrConflictDates(intNoOfAppsToRemove)
  431. Else
  432. arrFinalDates(intAFCnt) = FormatDateTime(dtmVDDate, DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  433. intAFCnt = intAFCnt + 1
  434. ReDim Preserve arrFinalDates(intAFCnt)
  435. End If
  436. Next
  437. ' It's open so add the day
  438. If intCCnt = 0 Then
  439. arrFinalDates(intAFCnt) = FormatDateTime(dtmVDDate, DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  440. intAFCnt = intAFCnt + 1
  441. ReDim Preserve arrFinalDates(intAFCnt)
  442. End If
  443. End If
  444. End If
  445. Next
  446. Next
  447. Else
  448. For intCnt = 0 To intNoOfApps
  449. ' Get the date
  450. dtmVDDate = DateAdd(DateInterval.DayOfYear, intCnt, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString))
  451. ' Get the day of the week
  452. intDayOfWeek = DatePart(DateInterval.Weekday, dtmVDDate)
  453. For intACnt = 1 To 7
  454. ' If the day of the week matches and that day has been
  455. ' Specified as a day to run
  456. If intDayOfWeek = intACnt Then
  457. If arrDOW(intACnt) Then
  458. intNoOfActualApps = intNoOfActualApps + 1
  459. arrFinalDates(intAFCnt) = FormatDateTime(dtmVDDate, DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  460. intAFCnt = intAFCnt + 1
  461. ReDim Preserve arrFinalDates(intAFCnt)
  462. End If
  463. End If
  464. Next
  465. Next
  466. End If
  467. End If
  468.  
  469. ' Set the new totals up
  470. intDaysClosed = intNoOfAppsToRemove
  471. intNoOfApps = intNoOfActualApps - intNoOfAppsToRemove
  472.  
  473. Case 1 ' Daily
  474.  
  475. intNoOfApps = DateDiff(DateInterval.DayOfYear, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString), CDate(calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString))
  476.  
  477. ' Collect the days the venue is closed
  478. ' Then remove those dates from the possible creations
  479. ' This only applies to Daily repeats
  480. ' Add the dates to the conflict date array
  481. If intNoOfApps >= 1 Then
  482. arrVDClosed = returnSiteClosedStatus()
  483. If arrVDClosed(0) = -1 Then
  484. For intCnt = 0 To intNoOfApps
  485. dtmVDDate = DateAdd(DateInterval.DayOfYear, intCnt, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString))
  486. For intCCnt = 0 To UBound(arrVDClosed, 1) - 1
  487. If DatePart(DateInterval.Weekday, dtmVDDate) = arrVDClosed(intCCnt) Then
  488. arrConflictDates(intNoOfAppsToRemove) = dtmVDDate
  489. intNoOfAppsToRemove = intNoOfAppsToRemove + 1
  490. ReDim Preserve arrConflictDates(intNoOfAppsToRemove)
  491. Else
  492. arrFinalDates(intAFCnt) = FormatDateTime(dtmVDDate, DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  493. intAFCnt = intAFCnt + 1
  494. ReDim Preserve arrFinalDates(intAFCnt)
  495. End If
  496. Next
  497. ' It's open so add the day
  498. If intCCnt = 0 Then
  499. arrFinalDates(intAFCnt) = FormatDateTime(dtmVDDate, DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  500. intAFCnt = intAFCnt + 1
  501. ReDim Preserve arrFinalDates(intAFCnt)
  502. End If
  503. Next
  504. End If
  505. End If
  506.  
  507. ' Set the new totals up
  508. intDaysClosed = intNoOfAppsToRemove
  509. intNoOfApps = intNoOfApps - intNoOfAppsToRemove + 1
  510.  
  511. Case 3 ' Monthly
  512. intNoOfApps = DateDiff(DateInterval.Month, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString), CDate(dtmSQLAdjust))
  513.  
  514. For intCnt = 0 To intNoOfApps - 1
  515. arrFinalDates(intAFCnt) = DateAdd(DateInterval.Month, intCnt, CDate(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString)) & " " & ddlAP_StartTime.SelectedValue
  516. intAFCnt = intAFCnt + 1
  517. ReDim Preserve arrFinalDates(intAFCnt)
  518. Next
  519.  
  520. Case 4 ' Ad Hoc Dates
  521. dstAdHoc = Session("dstAdHocDate")
  522. intNoOfApps = dstAdHoc.Tables(0).Rows.Count
  523.  
  524. For intCnt = 0 To intNoOfApps - 1
  525. arrFinalDates(intAFCnt) = dstAdHoc.Tables(0).Rows(intCnt).Item("AH_dtmEvent") & " " & ddlAP_StartTime.SelectedValue
  526. intAFCnt = intAFCnt + 1
  527. ReDim Preserve arrFinalDates(intAFCnt)
  528. Next
  529.  
  530. End Select
  531.  
  532. Else
  533.  
  534. arrFinalDates(intAFCnt) = FormatDateTime(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString, DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  535. intAFCnt = intAFCnt + 1
  536. ReDim Preserve arrFinalDates(intAFCnt)
  537.  
  538. End If
  539.  
  540. intAFCCnt = 0
  541.  
  542. ' Set the initial count to include those now driving
  543. intTR_NoOfKarts = intNoOfDriver
  544.  
  545. With dstData.Tables("AllTables")
  546. If .Rows.Count >= 1 Then
  547.  
  548. ' Clear the message out and setup the counters
  549. sTempNotice = ""
  550.  
  551. If ddlRF_RFID.Visible Then
  552. bRFOverride = True
  553. 'TS 16032016
  554. If bRepeat Then bRFOverride = False
  555. Else
  556. bRFOverride = False
  557. End If
  558.  
  559. ' Loop through all potential matches
  560. For intCnt = 0 To .Rows.Count - 1
  561.  
  562. intRF_MaxDrivers = .Rows(intCnt).Item("RF_MaxDrivers")
  563.  
  564. If bRFOverride Then
  565. bOverride = fnc_OverrideSelectedRace(ddlRF_RFID.SelectedValue, .Rows(intCnt).Item("RF_TRID"), .Rows(intCnt).Item("RF_RFID"))
  566. Else
  567. bOverride = False
  568. End If
  569.  
  570. bExists = False
  571.  
  572.  
  573. For intACount = 0 To UBound(arrFinalDates, 1) - 1
  574.  
  575. bIgnore = False
  576.  
  577. ' Only check it if it's a direct date match
  578. If FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) = FormatDateTime(arrFinalDates(intACount), DateFormat.ShortDate) Then
  579.  
  580. If FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime) = FormatDateTime(dtmStartTime, DateFormat.ShortTime) Then
  581. If Not bParticipentAdded Then
  582. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  583. bParticipentAdded = True
  584. Else
  585. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  586. bParticipentAdded = False
  587. End If
  588. Else
  589. ' This checks for events that have already started before the proposed event starts
  590. ' We need to check that to see if they end before the proposed event either ends whilst
  591. ' We are racing, or in the event of an hour event, ends after the event is running
  592. ' IF the duration is greater than 60 minutes then do this check
  593. dDuration = oGlobals.returnDuration(.Rows(intCnt).Item("RF_RFID"), .Rows(intCnt).Item("AD_NoParticipents"))
  594. If dDuration > 30 Then
  595. If FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime) < FormatDateTime(dtmStartTime, DateFormat.ShortTime) Then
  596. If FormatDateTime(.Rows(intCnt).Item("AP_EndTime"), DateFormat.ShortTime) > FormatDateTime(dtmStartTime, DateFormat.ShortTime) Then
  597. If Not bParticipentAdded Then
  598. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  599. bParticipentAdded = True
  600. Else
  601. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  602. bParticipentAdded = False
  603. End If
  604. End If
  605. End If
  606. If FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime) < FormatDateTime(dtmEndTime, DateFormat.ShortTime) Then
  607. If FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime) > FormatDateTime(dtmStartTime, DateFormat.ShortTime) Then
  608. If Not bParticipentAdded Then
  609. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  610. bParticipentAdded = True
  611. Else
  612. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  613. bParticipentAdded = False
  614. End If
  615. End If
  616. End If
  617. End If
  618.  
  619. ' This checks for events that will be running after the proposed event starts
  620. ' We just need to check to see if they end before the poposed event ends
  621. ' If the duration is only 30 minutes we need to check different options
  622. If dDuration <= 30 Then
  623. If FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime) < FormatDateTime(dtmStartTime, DateFormat.ShortTime) Then
  624. If FormatDateTime(.Rows(intCnt).Item("AP_EndTime"), DateFormat.ShortTime) > FormatDateTime(dtmStartTime, DateFormat.ShortTime) Then
  625. bIgnore = True
  626. If Not bParticipentAdded Then
  627. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  628. bParticipentAdded = True
  629. Else
  630. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  631. bParticipentAdded = False
  632. End If
  633. End If
  634. End If
  635. If FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime) > FormatDateTime(dtmStartTime, DateFormat.ShortTime) Then
  636. If FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime) < FormatDateTime(dtmEndTime, DateFormat.ShortTime) Then
  637. If Not bIgnore Then
  638. bIgnore = True
  639. If Not bParticipentAdded Then
  640. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  641. bParticipentAdded = True
  642. Else
  643. intTR_NoOfKarts = intTR_NoOfKarts + .Rows(intCnt).Item("AD_NoParticipents")
  644. bParticipentAdded = False
  645. End If
  646. End If
  647. End If
  648. End If
  649. End If
  650. End If
  651.  
  652. ' Clear the conflict flag for this loop
  653. bConflictExists = False
  654.  
  655.  
  656. ' Same start time
  657. sTempInternalNotice = fnc_SameStartTime(FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime), FormatDateTime(dtmStartTime, DateFormat.ShortTime), bRace, bOverride, intTR_NoOfKarts, .Rows(intCnt).Item("TR_MaxKarts"), intRF_MaxDrivers, .Rows(intCnt).Item("AP_ACID"), .Rows(intCnt).Item("RF_RFID"))
  658.  
  659. ' Mark it as a conflict and exit or continue
  660. If sTempInternalNotice <> "" Then
  661.  
  662. sTempNotice = sTempNotice & sTempInternalNotice
  663. bConflictExists = True
  664. bConflict = True
  665. arrConflict(intCnt) = intCnt
  666.  
  667. ' Store the date to remove it later
  668. ' So long as we haven't already got it in there
  669. bExists = False
  670. For intInCCnt = 0 To intAFCCnt - 1
  671. dtmCheck = .Rows(intCnt).Item("AP_dtmAppointmentStart") & " " & ddlAP_StartTime.SelectedValue
  672. dtmCheckII = arrRemoveDates(intInCCnt)
  673. If FormatDateTime(dtmCheckII, DateFormat.GeneralDate) = FormatDateTime(dtmCheck, DateFormat.GeneralDate) Then
  674. bExists = True
  675. Exit For
  676. End If
  677. Next
  678. If Not bExists Then
  679. arrRemoveDates(intAFCCnt) = FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  680. intAFCCnt = intAFCCnt + 1
  681. ReDim Preserve arrRemoveDates(intAFCCnt)
  682. End If
  683. End If
  684.  
  685. ' Ends whilst i'm racing
  686. ' Only check if the bConflictExists hasn't been
  687. ' For this particular date in the loop, there's no
  688. ' Point in checking if there's already a conflict
  689. If Not bConflictExists Then
  690. sTempInternalNotice = fnc_EndsWhilstRacing(FormatDateTime(.Rows(intCnt).Item("AP_EndTime"), DateFormat.ShortTime), FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime), FormatDateTime(dtmStartTime, DateFormat.ShortTime), bRace, bOverride, intTR_NoOfKarts, .Rows(intCnt).Item("TR_MaxKarts"), intRF_MaxDrivers, .Rows(intCnt).Item("AP_ACID"), .Rows(intCnt).Item("RF_RFID"))
  691. ' Mark it as a conflict and exit or continue
  692. If sTempInternalNotice <> "" Then
  693. sTempNotice = sTempNotice & sTempInternalNotice
  694. bConflictExists = True
  695. bConflict = True
  696. arrConflict(intCnt) = intCnt
  697.  
  698. ' Store the date to remove it later
  699. ' So long as we haven't already got it in there
  700. bExists = False
  701. For intInCCnt = 0 To intAFCCnt - 1
  702. dtmCheck = FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  703. dtmCheckII = FormatDateTime(arrRemoveDates(intInCCnt), DateFormat.GeneralDate)
  704. If FormatDateTime(dtmCheckII, DateFormat.GeneralDate) = FormatDateTime(dtmCheck, DateFormat.GeneralDate) Then
  705. bExists = True
  706. Exit For
  707. End If
  708. Next
  709. If Not bExists Then
  710. arrRemoveDates(intAFCCnt) = FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  711. intAFCCnt = intAFCCnt + 1
  712. ReDim Preserve arrRemoveDates(intAFCCnt)
  713. End If
  714. End If
  715. End If
  716.  
  717.  
  718. ' Starts whilst i'm racing
  719. ' Only check if the bConflictExists hasn't been
  720. ' For this particular date in the loop, there's no
  721. ' Point in checking if there's already a conflict
  722. If Not bConflictExists Then
  723.  
  724. sTempInternalNotice = fnc_StartsWhilstRacing(FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime), FormatDateTime(.Rows(intCnt).Item("AP_EndTime"), DateFormat.ShortTime), FormatDateTime(dtmStartTime, DateFormat.ShortTime), FormatDateTime(dtmEndTime, DateFormat.ShortTime), bRace, bOverride, intTR_NoOfKarts, .Rows(intCnt).Item("TR_MaxKarts"), intRF_MaxDrivers, .Rows(intCnt).Item("AP_ACID"), .Rows(intCnt).Item("RF_RFID"))
  725. If sTempInternalNotice <> "" Then
  726. sTempNotice = sTempNotice & sTempInternalNotice
  727. bConflictExists = True
  728. bConflict = True
  729. arrConflict(intCnt) = intCnt
  730. bExists = False
  731. For intInCCnt = 0 To intAFCCnt - 1
  732. dtmCheck = FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  733. dtmCheckII = FormatDateTime(arrRemoveDates(intInCCnt), DateFormat.GeneralDate)
  734. If FormatDateTime(dtmCheckII, DateFormat.GeneralDate) = FormatDateTime(dtmCheck, DateFormat.GeneralDate) Then
  735. bExists = True
  736. Exit For
  737. End If
  738. Next
  739. If Not bExists Then
  740. arrRemoveDates(intAFCCnt) = FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  741. intAFCCnt = intAFCCnt + 1
  742. ReDim Preserve arrRemoveDates(intAFCCnt)
  743. End If
  744. End If
  745. End If
  746. Else
  747. intTR_NoOfKarts = 0
  748. bParticipentAdded = False
  749. End If
  750. Next
  751.  
  752. If InStr(sTempNotice, "exceeds the activity center limit") Then
  753. .Rows(intCnt).Item("AP_Avail") = -1
  754. dstData.Tables("AllTables").AcceptChanges()
  755. End If
  756. If InStr(sTempNotice, "exceeds the events limit of") Then
  757. .Rows(intCnt).Item("AP_Avail") = -1
  758. dstData.Tables("AllTables").AcceptChanges()
  759. End If
  760. If InStr(sTempNotice, " are not comaptible") Then
  761. .Rows(intCnt).Item("AP_Avail") = -1
  762. dstData.Tables("AllTables").AcceptChanges()
  763. End If
  764. If InStr(sTempNotice, " that is exclusive") Then
  765. .Rows(intCnt).Item("AP_Avail") = -1
  766. dstData.Tables("AllTables").AcceptChanges()
  767. End If
  768. Next
  769.  
  770. Session("arrRemoveDates") = arrRemoveDates
  771. Session("arrFinalDates") = arrFinalDates
  772.  
  773. If bRace Then
  774. hidSRF_MinAge.Value = returnEventAge_Min(ddlRF_RFID.SelectedValue)
  775. hidSRF_MaxAge.Value = returnEventAge_Max(ddlRF_RFID.SelectedValue)
  776. Else
  777. hidSRF_MinAge.Value = 1
  778. hidSRF_MaxAge.Value = 100
  779. End If
  780.  
  781. ' Final check to make sure the venue will still be open
  782. If Not bConflict Then
  783. sTempInternalNotice = returnEndsAfterSiteCloses(FormatDateTime(dtmEndTime, DateFormat.ShortTime), FormatDateTime(returnVenueClosingTime, DateFormat.ShortTime), bRace)
  784. If sTempInternalNotice <> "" Then
  785. sTempNotice = sTempNotice & sTempInternalNotice
  786. bSiteClosed = True
  787. End If
  788. End If
  789.  
  790. ' Build the final dataset
  791. ' To show those that conflict
  792. pnlAvailability.Visible = True
  793. intACnt = 0
  794. If bRepeat Then
  795.  
  796. If bConflict Then
  797.  
  798. ' Loop through and grab the days that
  799. ' Won't get included and update the array
  800. ' Rebase the counter to include all closed days
  801. intConCount = UBound(arrConflictDates, 1)
  802. With dstData.Tables("AllTables")
  803.  
  804. ' Add the closed message if it applies
  805. Select Case ddlAP_Frequency.SelectedValue
  806. Case 0, 1, 2, 3
  807. dtmEndRun = calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString
  808. Case 4
  809. dstAdHoc = Session("dstAdHocDate")
  810. dtmEndRun = dstAdHoc.Tables(0).Rows(dstAdHoc.Tables(0).Rows.Count - 1).Item("AH_dtmEvent")
  811. End Select
  812.  
  813. If intDaysClosed > 0 Then
  814. sDtmDisplay = "<li>Conflicts were detected in the scheduling system.<br/><br/>If you proceed you will create a total of <b>|FINAL|</b> repeat booking(s) which will occur on a <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> basis until <b>" & FormatDateTime(dtmEndRun, DateFormat.ShortDate) & "</b>.<br/><br/>No entries will be created on the <b>" & intDaysClosed & "</b> day(s) that the venue is closed during the timeframe specified.<br/><br/>Entries will not be created on the following dates due to any existing bookings:<br/><b>"
  815. Else
  816. sDtmDisplay = "<li>Conflicts were detected in the scheduling system.<br/><br/>If you proceed you will create a total of <b>|FINAL|</b> repeat booking(s) which will occur on a <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> basis until <b>" & FormatDateTime(dtmEndRun, DateFormat.ShortDate) & "</b>.<br/><br/>Entries will not be created on the following dates due to any existing bookings:<br/><b>"
  817. End If
  818.  
  819. Dim tmpDates As New List(Of Date)
  820. For intCnt = 0 To UBound(arrRemoveDates, 1) - 1
  821. tmpDates.Add(FormatDateTime(arrRemoveDates(intCnt), DateFormat.GeneralDate))
  822. Next
  823. tmpDates.Sort()
  824.  
  825. ' Sort out the dates to display
  826. For intCnt = 0 To tmpDates.Count - 1
  827. sDtmDisplay = sDtmDisplay & " | " & FormatDateTime(tmpDates(intCnt), DateFormat.GeneralDate)
  828. intNoOfApps = intNoOfApps - 1
  829. intACnt = intACnt + 1
  830. If intACnt = 4 Then
  831. sDtmDisplay = sDtmDisplay & "<br/>"
  832. intACnt = 0
  833. End If
  834. Next
  835.  
  836. ' Tidy up the string and replace the |FINAL|
  837. ' Variables with the actual number left to be created
  838. sDtmDisplay = Replace(sDtmDisplay, "|FINAL|", intNoOfApps) & "</b>"
  839.  
  840. ' Final catch to make sure 0's are caught
  841. If intNoOfApps <= 0 Then
  842. sDtmDisplay = "<li>Conflicts were detected in the scheduling system against <b>ALL</b> of the dates you have selected, therefore you cannot create the bookings."
  843. btnAddClients.Enabled = False
  844. Else
  845. sDtmDisplay = Replace(sDtmDisplay, "|FINAL|", intNoOfApps) & "</b>"
  846. btnAddClients.Enabled = True
  847. End If
  848.  
  849. End With
  850.  
  851. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  852. lbl_Availability.Text = sDtmDisplay
  853. lbl_Availability.Text = lbl_Availability.Text & "<br/><br/>Click <a href='DailyCalendar.aspx?CO_COID=" & ddlCO_COID.SelectedValue & "&VE_VEID=" & ddlVE_VEID.SelectedValue & "&TR_TRID=" & ddlTR_TRID.SelectedValue & "&ap_lapid=" & hidAP_APID_Primary.Value & "&ap_lclid=" & hidAP_CLID_Primary.Value & "&dtmDate=" & FormatDateTime(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString, DateFormat.ShortDate) & "'>HERE</a> to view the calendar."
  854. trRepeater.Visible = False
  855. trProceed.Visible = True
  856. txt_AP_NoDrivers.Text = "0"
  857. txt_AP_NoDrivers_Alt.Text = "0"
  858.  
  859. Else
  860.  
  861. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  862. ' Added to prevent silly messages getting returned,
  863. ' If someone has selected a monthly/weekly schedule
  864. ' But not put enough time into make a difference
  865. If intNoOfApps = 0 Then
  866. If intDaysClosed > 0 Then
  867. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will only create <b>1</b> booking because the end date specified occurs before the next <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> occurrence would be met.<br/>No entries will be created on the <b>" & intDaysClosed & "</b> day(s) that the venue is closed during the timeframe specified."
  868. Else
  869. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will only create <b>1</b> booking because the end date specified occurs before the next <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> occurrence would be met."
  870. End If
  871. Else
  872. Select Case ddlAP_Frequency.SelectedValue
  873. Case 0, 1, 2, 3
  874. dtmEndRun = calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString
  875. Case 4
  876. dstAdHoc = Session("dstAdHocDate")
  877. dtmEndRun = dstAdHoc.Tables(0).Rows(dstAdHoc.Tables(0).Rows.Count - 1).Item("AH_dtmEvent")
  878. End Select
  879. If intDaysClosed > 0 Then
  880. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will create a total of <b>" & intNoOfApps & "</b> repeat booking(s) which will occur on a <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> basis until <b>" & FormatDateTime(dtmEndRun, DateFormat.ShortDate) & "</b>.<br/>No entries will be created on the <b>" & intDaysClosed & "</b> day(s) that the venue is closed during the timeframe specified."
  881. Else
  882. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will create a total of <b>" & intNoOfApps & "</b> repeat booking(s) which will occur on a <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> basis until <b>" & FormatDateTime(dtmEndRun, DateFormat.ShortDate) & "</b>."
  883. End If
  884. End If
  885. lbl_Availability.Text = sDtmDisplay
  886. trRepeater.Visible = False
  887. trProceed.Visible = True
  888. txt_AP_NoDrivers.Text = "0"
  889. txt_AP_NoDrivers_Alt.Text = "0"
  890. btnAddClients.Enabled = True
  891.  
  892. End If
  893.  
  894. Else
  895.  
  896. ' New check to see if we have an identical match or not
  897. bSameEvent = False
  898. Dim bConflictMatched As Boolean = False
  899.  
  900. ' Loop through all potential matches
  901. For intCnt = 0 To .Rows.Count - 1
  902.  
  903. intRF_MaxDrivers = .Rows(intCnt).Item("RF_MaxDrivers")
  904.  
  905. For intACount = 0 To UBound(arrFinalDates, 1) - 1
  906.  
  907. bIgnore = False
  908.  
  909. ' Only check it if it's a direct date and format match
  910. If FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) = FormatDateTime(arrFinalDates(intACount), DateFormat.ShortDate) Then
  911.  
  912. ' Same start time
  913. sTempInternalNotice = fnc_SameStartTime_AddToEvent(FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime), FormatDateTime(dtmStartTime, DateFormat.ShortTime), .Rows(intCnt).Item("AP_ACID"), .Rows(intCnt).Item("RF_RFID"))
  914.  
  915. ' Mark it as a conflict and exit or continue
  916. If sTempInternalNotice <> "" Then
  917.  
  918. If Not bConflictMatched Then
  919. sTempNotice = sTempNotice & sTempInternalNotice
  920. bConflict = True
  921. arrConflict(intCnt) = intCnt
  922. bConflictMatched = True
  923. End If
  924.  
  925. ' Store the date to remove it later
  926. ' So long as we haven't already got it in there
  927. bExists = False
  928. For intInCCnt = 0 To intAFCCnt - 1
  929. dtmCheck = .Rows(intCnt).Item("AP_dtmAppointmentStart") & " " & ddlAP_StartTime.SelectedValue
  930. dtmCheckII = arrRemoveDates(intInCCnt)
  931. If FormatDateTime(dtmCheckII, DateFormat.GeneralDate) = FormatDateTime(dtmCheck, DateFormat.GeneralDate) Then
  932. bExists = True
  933. Exit For
  934. End If
  935. Next
  936. If Not bExists Then
  937. arrRemoveDates(intAFCCnt) = FormatDateTime(.Rows(intCnt).Item("AP_dtmAppointmentStart"), DateFormat.ShortDate) & " " & ddlAP_StartTime.SelectedValue
  938. intAFCCnt = intAFCCnt + 1
  939. ReDim Preserve arrRemoveDates(intAFCCnt)
  940. End If
  941. End If
  942.  
  943. Else
  944. intTR_NoOfKarts = 0
  945. bParticipentAdded = False
  946. End If
  947. Next
  948.  
  949. Next
  950.  
  951. Session("arrRemoveDates") = arrRemoveDates
  952. Session("arrFinalDates") = arrFinalDates
  953. dstDataClone = New DataSet
  954.  
  955. If bConflict Then
  956.  
  957. dstTable = New DataTable
  958. With dstData.Tables("AllTables")
  959.  
  960. ' Add the columns
  961. For intCnt = 0 To .Columns.Count - 1
  962. dstCol = New DataColumn(.Columns(intCnt).ColumnName, .Columns(intCnt).DataType)
  963. dstTable.Columns.Add(dstCol)
  964. Next
  965.  
  966. ' Add the rows
  967. For intCnt = 0 To .Rows.Count - 1
  968. If arrConflict(intCnt) = intCnt Then
  969. dstRow = dstTable.NewRow
  970. For intCCnt = 0 To .Columns.Count - 1
  971. dstRow(intCCnt) = .Rows(intCnt).Item(intCCnt)
  972. Next
  973. dstTable.Rows.Add(dstRow)
  974. End If
  975. Next
  976.  
  977. ' Add the table
  978. dstDataClone.Tables.Add(dstTable)
  979.  
  980. End With
  981.  
  982. End If
  983.  
  984. ' Final update to sort out empty references for meetings
  985. If bConflict Then
  986. If Not bRace Then
  987. For intCnt = 0 To dstDataClone.Tables(0).Rows.Count - 1
  988. With dstDataClone.Tables(0)
  989. dtmStart = FormatDateTime(.Rows(intCnt).Item("AP_StartTime"), DateFormat.ShortTime)
  990. dtmEnd = FormatDateTime(.Rows(intCnt).Item("AP_EndTime"), DateFormat.ShortTime)
  991. dMinute = DateDiff(DateInterval.Minute, dtmStart, dtmEnd)
  992. If .Rows(intCnt).Item("RF_Name") & "" = "" Then .Rows(intCnt).Item("RF_Name") = "Room Hire"
  993. dDuration = oGlobals.returnDuration(.Rows(0).Item("RF_RFID"), .Rows(0).Item("AD_NoParticipents"))
  994. If dDuration & "" = "" Then .Rows(intCnt).Item("RF_Duration") = dMinute
  995. If .Rows(intCnt).Item("AP_Avail") & "" = "" Then .Rows(intCnt).Item("AP_Avail") = 0
  996. .Rows(intCnt).Item("RF_Duration") = dDuration
  997. dstDataClone.AcceptChanges()
  998. End With
  999. Next
  1000. End If
  1001. End If
  1002.  
  1003. ' Sort out the duration as we've got the new method
  1004. If dstDataClone.Tables.Count >= 1 Then
  1005. For intCnt = 0 To dstDataClone.Tables(0).Rows.Count - 1
  1006. With dstDataClone.Tables(0)
  1007. dDuration = oGlobals.returnDuration(.Rows(0).Item("RF_RFID"), .Rows(0).Item("AD_NoParticipents"))
  1008. If dDuration & "" = "" Then .Rows(intCnt).Item("RF_Duration") = dMinute
  1009. .Rows(intCnt).Item("RF_Duration") = dDuration
  1010. dstDataClone.AcceptChanges()
  1011. End With
  1012. Next
  1013. End If
  1014.  
  1015. ' Either show the conflicting events
  1016. ' Or hide and display the continue panels
  1017. ' And remove any people count!
  1018. pnlAvailability.Visible = True
  1019.  
  1020. If bConflict Then
  1021. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  1022. lbl_Details.Text = "<b>Please Note:</b> The number shown in 'Spaces Left' refers to the number of spaces that will be left <b>AFTER</b> the booking you are currently placing.<br/><br/>"
  1023. lbl_Availability.Text = sTempNotice
  1024. rptAvailability.DataSource = dstDataClone
  1025. rptAvailability.DataBind()
  1026. trRepeater.Visible = True
  1027. trProceed.Visible = False
  1028. lbl_Availability.Text = lbl_Availability.Text & "<br/><br/>Click <a href='DailyCalendar.aspx?CO_COID=" & ddlCO_COID.SelectedValue & "&VE_VEID=" & ddlVE_VEID.SelectedValue & "&TR_TRID=" & ddlTR_TRID.SelectedValue & "&AP_LAPID=" & hidAP_APID_Primary.Value & "&AP_LCLID=" & hidAP_CLID_Primary.Value & "&dtmDate=" & FormatDateTime(calAP_dtmAppointmentStart.SelectedDate.Value.ToShortDateString, DateFormat.ShortDate) & "'>HERE</a> to view the calendar."
  1029. btnAddClients.Enabled = True
  1030. Else
  1031. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  1032. lbl_Availability.Text = "<li>There were no conflicts found.</li>"
  1033. trRepeater.Visible = False
  1034. trProceed.Visible = True
  1035. btnAddClients.Enabled = True
  1036. End If
  1037.  
  1038. End If
  1039.  
  1040. ' Final check for venue closed situation
  1041. If bSiteClosed Then
  1042. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  1043. lbl_Availability.Text = "<li>There were no conflicts found, however the event is scheduled to finish <b>after the venue has closed.</b> You may proceed if you wish, but it's at your discretion.</li>"
  1044. trRepeater.Visible = False
  1045. trProceed.Visible = True
  1046. btnAddClients.Enabled = True
  1047. End If
  1048.  
  1049. Else
  1050.  
  1051. ' Collect info for checking against
  1052. ' Minimum/maximum age requirements
  1053. ' Default adhocs to untouchable levelts as we don't
  1054. ' Care what they are because the organiser is assuming
  1055. ' Responsibility for all that when they create the event
  1056. If bAdHoc Or bMeeting Or bBlock Then
  1057. hidSRF_MinAge.Value = 1
  1058. hidSRF_MaxAge.Value = 100
  1059. Else
  1060. hidSRF_MinAge.Value = returnEventAge_Min(ddlRF_RFID.SelectedValue)
  1061. hidSRF_MaxAge.Value = returnEventAge_Max(ddlRF_RFID.SelectedValue)
  1062. End If
  1063.  
  1064. Session("arrFinalDates") = arrFinalDates
  1065.  
  1066. ' Final check to make sure the venue will still be open
  1067. If Not bConflict Then
  1068. sTempInternalNotice = returnEndsAfterSiteCloses(FormatDateTime(dtmEndTime, DateFormat.ShortTime), FormatDateTime(returnVenueClosingTime, DateFormat.ShortTime), bRace)
  1069. ' Mark it as a conflict and exit or continue
  1070. If sTempInternalNotice <> "" Then
  1071. sTempNotice = sTempNotice & sTempInternalNotice
  1072. bSiteClosed = True
  1073. End If
  1074. End If
  1075.  
  1076. ' Display the panel
  1077. pnlAvailability.Visible = True
  1078.  
  1079. ' Sort out the message dending on the repeat status
  1080. If bRepeat Then
  1081.  
  1082. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  1083. ' Added to prevent silly messages getting returned,
  1084. ' If someone has selected a monthly/weekly schedule
  1085. ' But not put enough time into make a difference
  1086. If intNoOfApps = 0 Then
  1087. If intDaysClosed > 0 Then
  1088. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will only create <b>1</b> booking because the end date specified occurs before the next <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> occurrence would be met.<br/>No entries will be created on the <b>" & intDaysClosed & "</b> day(s) that the venue is closed during the timeframe specified."
  1089. Else
  1090. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will only create <b>1</b> booking because the end date specified occurs before the next <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> occurrence would be met."
  1091. End If
  1092. Else
  1093. If intDaysClosed > 0 Then
  1094. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will create a total of <b>" & intNoOfApps & "</b> repeat booking(s) which will occur on a <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> basis until <b>" & FormatDateTime(calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString, DateFormat.ShortDate) & "</b>.<br/>No entries will be created on the <b>" & intDaysClosed & "</b> day(s) that the venue is closed during the timeframe specified."
  1095. Else
  1096. sDtmDisplay = "<li>There were no conflicts found.<br/>If you proceed you will create a total of <b>" & intNoOfApps & "</b> repeat booking(s) which will occur on a <b>" & ddlAP_Frequency.Items(ddlAP_Frequency.SelectedIndex).Text & "</b> basis until <b>" & FormatDateTime(calAP_dtmAppointmentEnd.SelectedDate.Value.ToShortDateString, DateFormat.ShortDate) & "</b>."
  1097. End If
  1098. End If
  1099. lbl_Availability.Text = sDtmDisplay
  1100. trRepeater.Visible = False
  1101. trProceed.Visible = True
  1102. txt_AP_NoDrivers.Text = "0"
  1103. btnAddClients.Enabled = True
  1104.  
  1105. Else
  1106.  
  1107. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  1108. lbl_Availability.Text = "<li>There were no conflicts found.</li>"
  1109. trRepeater.Visible = False
  1110. trProceed.Visible = True
  1111. btnAddClients.Enabled = True
  1112.  
  1113. End If
  1114.  
  1115. ' Final check for venue closed situation
  1116. If bSiteClosed Then
  1117. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  1118. lbl_Availability.Text = "<li>There were no conflicts found, however the event is scheduled to finish <b>after the venue has closed.</b> You may proceed if you wish, but it's at your discretion.</li>"
  1119. trRepeater.Visible = False
  1120. trProceed.Visible = True
  1121. btnAddClients.Enabled = True
  1122. End If
  1123. End If
  1124.  
  1125. End With
  1126.  
  1127. Else
  1128. lbl_AVTitle.Text = "<b><a name='avail'>Availability</a></b>"
  1129. lbl_Availability.Text = "<li>There were no conflicts found.</li>"
  1130. trAvailability.Visible = True
  1131. pnlAvailability.Visible = True
  1132. trRepeater.Visible = False
  1133. trProceed.Visible = True
  1134. btnAddClients.Enabled = True
  1135. End If
  1136.  
  1137. ' Final catch to clean up messages
  1138. If InStr(sTempNotice, "There is an identical event") Then
  1139. lbl_Details.Visible = True
  1140. Else
  1141. lbl_Details.Visible = False
  1142. End If
  1143.  
  1144. ' Save the array
  1145. If Not IsNothing(arrConflictDates) Then Session("arrConflictDates") = arrConflictDates
  1146.  
  1147. ' Kill the connection if it's still open
  1148. If sqlConn.State <> ConnectionState.Closed Then sqlConn.Close()
  1149.  
  1150. End If
  1151.  
  1152. End Using
  1153.  
  1154. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement