home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblScheduleedit.aspx.vb < prev    next >
Text File  |  2014-12-14  |  79KB  |  1,631 lines

  1. Imports System.Data
  2. Imports System.Data.Common
  3. Imports System.Xml
  4. Imports System.IO
  5. Imports System.Data.OleDb
  6. Imports Microsoft.Exchange.WebServices.Data
  7. Imports Microsoft.Exchange.WebServices.Autodiscover
  8. Imports System.Net
  9. Imports System.Net.Security
  10. Imports System.Security.Cryptography.X509Certificates
  11.  
  12. '
  13. ' ASP.NET code-behind class (Page)
  14. '
  15.  
  16. Partial Class tblScheduleedit
  17.     Inherits AspNetMaker7_tfpssnet
  18.  
  19.     ' Page object
  20.     Public tblSchedule_edit As ctblSchedule_edit
  21.  
  22.     '
  23.     ' Page Class
  24.     '
  25.     Class ctblSchedule_edit
  26.         Inherits AspNetMakerPage
  27.         Implements IDisposable        
  28.  
  29.         ' Used by system generated functions
  30.         Private RsWrk As Object, sSqlWrk As String, sWhereWrk As String
  31.  
  32.         Private arwrk As Object
  33.  
  34.         Private armultiwrk() As String        
  35.  
  36.         ' Page URL
  37.         Public ReadOnly Property PageUrl() As String
  38.             Get
  39.                 Dim Url As String = ew_CurrentPage() & "?"
  40.                 If tblSchedule.UseTokenInUrl Then Url = Url & "t=" & tblSchedule.TableVar & "&" ' Add page token
  41.                 Return Url    
  42.             End Get
  43.         End Property
  44.  
  45.         ' Validate page request
  46.         Public Function IsPageRequest() As Boolean
  47.             Dim Result As Boolean
  48.             If tblSchedule.UseTokenInUrl Then
  49.                 Result = False
  50.                 If ObjForm IsNot Nothing Then
  51.                     Result = (tblSchedule.TableVar = ObjForm.GetValue("t"))
  52.                 End If
  53.                 If ew_Get("t") <> "" Then
  54.                     Result = (tblSchedule.TableVar = ew_Get("t"))
  55.                 End If
  56.                 Return Result
  57.             End If
  58.             Return True            
  59.         End Function    
  60.  
  61.         ' tblSchedule
  62.         Public Property tblSchedule() As ctblSchedule
  63.             Get                
  64.                 Return ParentPage.tblSchedule
  65.             End Get
  66.             Set(ByVal v As ctblSchedule)
  67.                 ParentPage.tblSchedule = v    
  68.             End Set    
  69.         End Property
  70.  
  71.         ' tblSchedule
  72.         Public Property tblEmployees() As ctblEmployees
  73.             Get                
  74.                 Return ParentPage.tblEmployees
  75.             End Get
  76.             Set(ByVal v As ctblEmployees)
  77.                 ParentPage.tblEmployees = v    
  78.             End Set    
  79.         End Property
  80.  
  81.         '
  82.         '  Constructor
  83.         '  - init objects
  84.         '  - open connection
  85.         '
  86.         Public Sub New(ByRef APage As AspNetMaker7_tfpssnet)                
  87.             m_ParentPage = APage
  88.             m_Page = Me    
  89.             m_PageID = "edit"
  90.             m_PageObjName = "tblSchedule_edit"
  91.             m_PageObjTypeName = "ctblSchedule_edit"
  92.  
  93.             ' Table Name
  94.             m_TableName = "tblSchedule"
  95.  
  96.             ' Initialize table object
  97.             tblSchedule = New ctblSchedule(Me)
  98.             tblEmployees = New ctblEmployees(Me)
  99.  
  100.             ' Connect to database
  101.             Conn = New cConnection()
  102.         End Sub
  103.  
  104.         '
  105.         '  Subroutine Page_Init
  106.         '  - called before page main
  107.         '  - check Security
  108.         '  - set up response header
  109.         '  - call page load events
  110.         '
  111.         Public Sub Page_Init()
  112.             Security = New cAdvancedSecurity(Me)
  113.             If Not Security.IsLoggedIn() Then Security.AutoLogin()
  114.             If Not Security.IsLoggedIn() Then
  115.                 Security.SaveLastUrl()
  116.                 Page_Terminate("login.aspx")
  117.             End If
  118.  
  119.             ' Table Permission loading event
  120.             Security.TablePermission_Loading()
  121.             Security.LoadCurrentUserLevel(TableName)
  122.  
  123.             ' Table Permission loaded event
  124.             Security.TablePermission_Loaded()
  125.             If Not Security.CanEdit Then
  126.                 Security.SaveLastUrl()
  127.                 Page_Terminate("tblSchedulelist.aspx")
  128.             End If
  129.  
  130.             ' User ID loading event
  131.             Security.UserID_Loading()
  132.             If Security.IsLoggedIn() Then Call Security.LoadUserID()
  133.  
  134.             ' User ID loaded event
  135.             Security.UserID_Loaded()
  136.             If Security.IsLoggedIn() And ew_Empty(Security.CurrentUserID) Then
  137.                 Message = "You do not have the right permission to view the page"
  138.                 Page_Terminate("tblSchedulelist.aspx")
  139.             End If
  140.  
  141.             ' Global page loading event (in ewglobal*.vb)
  142.             ParentPage.Page_Loading()
  143.  
  144.             ' Page load event, used in current page
  145.             Page_Load()
  146.         End Sub
  147.  
  148.         '
  149.         '  Class terminate
  150.         '  - clean up page object
  151.         '
  152.         Public Sub Dispose() Implements IDisposable.Dispose
  153.             Page_Terminate("")
  154.         End Sub
  155.  
  156.         '
  157.         '  Sub Page_Terminate
  158.         '  - called when exit page
  159.         '  - clean up connection and objects
  160.         '  - if URL specified, redirect to URL
  161.         '
  162.         Sub Page_Terminate(url As String)
  163.  
  164.             ' Page unload event, used in current page
  165.             Page_Unload()
  166.  
  167.             ' Global page unloaded event (in ewglobal*.vb)
  168.             ParentPage.Page_Unloaded()
  169.  
  170.             ' Close connection
  171.             Conn.Dispose()
  172.             Security = Nothing
  173.             tblSchedule.Dispose()
  174.             tblEmployees.Dispose()
  175.  
  176.             ' Go to URL if specified
  177.             If url <> "" Then
  178.                 HttpContext.Current.Response.Clear()
  179.                 HttpContext.Current.Response.Redirect(url)
  180.             End If
  181.         End Sub
  182.  
  183.     '
  184.     ' Page main processing
  185.         '
  186.         Public PSSSendEmailConfirmation As Boolean
  187.  
  188.         Public PSSSyncExchangeCalendar As Boolean
  189.  
  190.     Sub Page_Main()
  191.             Dim tlcsub As New AspNetMaker7_tfpssnet
  192.             PSSSendEmailConfirmation = tlcsub.tlcGetPSSEmailConfirmation()
  193.             PSSSyncExchangeCalendar = tlcsub.tlcGetPSSUpdateExchangeCalendar()
  194.  
  195.         ' Load key from QueryString
  196.         If ew_Get("schSchID") <> "" Then
  197.             tblSchedule.schSchID.QueryStringValue = ew_Get("schSchID")
  198.         End If
  199.  
  200.         ' Create form object
  201.         ObjForm = New cFormObj
  202.         If ObjForm.GetValue("a_edit") <> "" Then
  203.             tblSchedule.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
  204.             LoadFormValues() ' Get form values
  205.  
  206.             ' Validate Form
  207.             If Not ValidateForm() Then
  208.                 tblSchedule.CurrentAction = "" ' Form error, reset action
  209.                 Message = ParentPage.gsFormError
  210.                 LoadRow() ' Restore row
  211.                 RestoreFormValues() ' Restore form values if validate failed
  212.             End If
  213.         Else
  214.             tblSchedule.CurrentAction = "I" ' Default action is display
  215.         End If
  216.  
  217.         ' Check if valid key
  218.         If ew_Empty(tblSchedule.schSchID.CurrentValue) Then Page_Terminate("tblSchedulelist.aspx") ' Invalid key, return to list
  219.         Select Case tblSchedule.CurrentAction
  220.             Case "I" ' Get a record to display
  221.                 If Not LoadRow() Then ' Load Record based on key
  222.                     Message = "No records found" ' No record found
  223.                     Page_Terminate("tblSchedulelist.aspx") ' No matching record, return to list
  224.                 End If
  225.             Case "U" ' Update
  226.                     tblSchedule.SendEmail = False ' Send email on update success
  227.                     Dim tmpRsOld As New OrderedDictionary, tmpRsNew As New OrderedDictionary
  228.                     If EditRow(tmpRsOld, tmpRsNew) Then ' Update Record based on key
  229.                         Message = "Update succeeded" ' Update success
  230.                         UpdateCalendarEntry(tmpRsOld, tmpRsNew)
  231.                         Dim sReturnUrl As String = tblSchedule.ReturnUrl
  232.                         Page_Terminate(sReturnUrl) ' Return to caller
  233.                     Else
  234.                         LoadRow() ' Restore row
  235.                         RestoreFormValues() ' Restore form values if update failed
  236.                     End If
  237.             End Select
  238.  
  239.             ' Render the record
  240.             tblSchedule.RowType = EW_ROWTYPE_EDIT ' Render as edit
  241.  
  242.             ' Render row
  243.             RenderRow()
  244.         End Sub
  245.  
  246.         Sub UpdateCalendarEntry(ByRef tmpRsOld As OrderedDictionary, ByVal tmpRsNew As OrderedDictionary)
  247.             'Dim service As New ExchangeService(requestedServerVersion:=ExchangeVersion.Exchange2010)
  248.             Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP1)
  249.             Dim tmpSchDate As Date, tmpEvtDescription As String, tmpPrtDescription As String, tmpCallTime As Date
  250.             Dim tmpStartTime As Date, tmpEndTime As Date, tmpOutTime As Date, tmpLocDescription As String, tmpPosDescription As String, tmpStDescription As String
  251.             Dim tmpTypDescription As String, tmpEmpName As String, tmpEmail As String, tmpBody As String, tmpAction As String = "", tmpStatus As String, tmpType As String, tmpNotes As String
  252.             Dim intResult As Integer, tmpMessage As String, tmpNewStatus As String, smtpStatus As Boolean, smtpMessage As String
  253.             Dim tlcsub As New AspNetMaker7_tfpssnet
  254.             'intResult = tlcsub.tlcGetEventInfo(tblSchedule.schSchID.CurrentValue, tmpSchDate, tmpEvtDescription, tmpPrtDescription, tmpCallTime, tmpStartTime, tmpEndTime, tmpOutTime, tmpLocDescription, tmpPosDescription, tmpStDescription, tmpTypDescription, tmpEmpName, tmpEmail, tmpStatus, tmpNotes)
  255.             tmpSchDate = tmpRsOld("schDate")
  256.             tmpEvtDescription = tlcsub.SafeDBNull(tlcsub.tlcGetEventDesc(tmpRsOld("schEvtID")))
  257.             tmpPrtDescription = tlcsub.SafeDBNull(tlcsub.tlcGetPartDesc(tmpRsOld("schPartsID")))
  258.             If Not IsDBNull(tmpRsOld("schCallTime")) Then
  259.                 tmpCallTime = Format(tmpRsOld("schCallTime"), "hh:mm:ss tt")
  260.             Else
  261.                 tmpCallTime = "12:00:00 AM"
  262.             End If
  263.             If Not IsDBNull(tmpRsOld("schStartTime")) Then
  264.                 tmpStartTime = Format(tmpRsOld("schStartTime"), "hh:mm:ss tt")
  265.             Else
  266.                 tmpStartTime = "12:00:00 AM"
  267.             End If
  268.             If Not IsDBNull(tmpRsOld("schEndTime")) Then
  269.                 tmpEndTime = Format(tmpRsOld("schEndTime"), "hh:mm:ss tt")
  270.             Else
  271.                 tmpEndTime = "12:00:00 AM"
  272.             End If
  273.             If Not IsDBNull(tmpRsOld("schOutTime")) Then
  274.                 tmpOutTime = Format(tmpRsOld("schOutTime"), "hh:mm:ss tt")
  275.             Else
  276.                 tmpOutTime = "12:00:00 AM"
  277.             End If
  278.             tmpLocDescription = tlcsub.SafeDBNull(tlcsub.tlcGetLocationName(tmpRsOld("schLocID")))
  279.             tmpPosDescription = tlcsub.SafeDBNull(tlcsub.tlcGetPositionName(tmpRsOld("schPosID")))
  280.             tmpTypDescription = tlcsub.SafeDBNull(tlcsub.tlcGetTypeDesc(tmpRsOld("schTypID")))
  281.             tmpEmpName = tlcsub.SafeDBNull(tlcsub.tlcGetEmployeeName(tmpRsOld("schEmpID")))
  282.             tmpNotes = tlcsub.SafeDBNull(tmpRsOld("schNotes"))
  283.             'tmpEmail = ew_Session("tfpssnet_Status_UserEmail")
  284.             tmpEmail = tlcsub.tlcGetEmployeeEmail(tmpRsOld("schEmpID"))
  285.             If InStr(tmpEmail, "@tfc.org") = 0 And PSSSyncExchangeCalendar = False Then Exit Sub
  286.             Select Case tmpRsOld("schStatus")
  287.                 Case 1
  288.                     tmpAction = "A"
  289.                     tmpStatus = "BUSY"
  290.                     tmpType = "C"
  291.                 Case 2
  292.                     tmpAction = "D"
  293.                     tmpType = "U"
  294.                 Case 3
  295.                     tmpAction = "D"
  296.                     tmpType = "X"
  297.                 Case 4
  298.                     tmpAction = "A"
  299.                     tmpStatus = "TENTATIVE"
  300.                     tmpType = "T"
  301.             End Select
  302.             Select Case tmpRsNew("schStatus")
  303.                 Case 1
  304.                     tmpNewStatus = "Confirmed"
  305.                     tmpStDescription = "Confirmed"
  306.                 Case 2
  307.                     tmpNewStatus = "Un-confirmed"
  308.                     tmpStDescription = "Un-confirmed"
  309.                 Case 3
  310.                     tmpNewStatus = "Cannot Work"
  311.                     tmpStDescription = "Cannot Work"
  312.                 Case 4
  313.                     tmpNewStatus = "Tentative"
  314.                     tmpStDescription = "Tentative"
  315.             End Select
  316.  
  317.             If PSSSendEmailConfirmation = True Or PSSSyncExchangeCalendar = True Then
  318.                 'Add a valid EWS service end point here or user Autodiscover
  319.                 'service.Url = New Uri("https://server14/ews/exchange.asmx")
  320.                 service.Url = New Uri("https://outlook.office365.com/EWS/Exchange.asmx")
  321.  
  322.                 'Add a valid user credentials
  323.                 'service.Credentials = New WebCredentials("prodservices", "production88", "Business")
  324.                 service.Credentials = New WebCredentials("productionservices@tfc.org", "production88")
  325.                 service.AutodiscoverUrl("productionservices@tfc.org", AddressOf RedirectionUrlValaditionCallBack)
  326.  
  327.                 'To address the SSL challenge
  328.                 ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
  329.             End If
  330.  
  331.             If tlcsub.tlcGetPSSEmailConfirmation() = True Then
  332.                 If tmpRsOld("schStatus") <> tmpRsNew("schStatus") Then
  333.                     tmpMessage = " for the following event:<br><br>"
  334.                     tmpMessage = tmpMessage & "<b>Employee:</b> " & tmpEmpName & "<br> "
  335.                     tmpMessage = tmpMessage & "<b>Date:</b> " & ew_FormatDateTime(tmpSchDate, 2) & "<br> "
  336.                     tmpMessage = tmpMessage & "<b>Event:</b> " & tmpEvtDescription & "<br> "
  337.                     tmpMessage = tmpMessage & "<b>Part:</b> " & tmpPrtDescription & "<br>"
  338.                     tmpMessage = tmpMessage & "<b>Call Time:</b> " & ew_FormatDateTime(tmpCallTime, 14) & "<br>"
  339.                     tmpMessage = tmpMessage & "<b>Start Time:</b> " & ew_FormatDateTime(tmpStartTime, 14) & "<br>"
  340.                     'tmpMessage = tmpMessage & "<b>End Time:</b> " & ew_FormatDateTime(tmpEndTime, 14) & "<br>"
  341.                     'tmpMessage = tmpMessage & "<b>Out Time:</b> " & ew_FormatDateTime(tmpOutTime, 14) & "<br>"
  342.                     tmpMessage = tmpMessage & "<b>Location:</b> " & tmpLocDescription & "<br>"
  343.                     tmpMessage = tmpMessage & "<b>Position:</b> " & tmpPosDescription & "<br>"
  344.                     tmpMessage = tmpMessage & "<b>Status:</b> " & tmpNewStatus & "<br>"
  345.                     tmpMessage = tmpMessage & "<b>Type:</b> " & tmpTypDescription & "<br>"
  346.                     tmpMessage = tmpMessage & "<b>Notes:</b> " & tmpNotes & "<br><br>"
  347.                     tmpMessage = tmpMessage & "sent from PSS tblScheduleedit."
  348.                     'ew_SendEmail("prodservices@tfchurch.org", "kirkmanton@tfchurch.org", "", "", "PSS Event status change for " & ew_Session("tfpssnet_Status_UserName"), tmpMessage, "html")
  349.                     Try
  350.                         'Create new message object and set properties required to send a mail
  351.                         Dim msg As EmailMessage = New EmailMessage(service)
  352.                         msg.Subject = "PSS Event status change by " & ew_Session("tfpssnet_Status_UserName")
  353.                         msg.Body = tmpMessage
  354.                         'msg.ToRecipients.Add("tony.clayton@suddenlink.net")
  355.                         'msg.ToRecipients.Add("tonyc@tfchurch.org")
  356.                         msg.ToRecipients.Add("kirkmanton@tfc.org")
  357.                         msg.From = "productionservices@tfc.org"
  358.                         msg.SendAndSaveCopy()
  359.                         '                                            Message = "Email sent."
  360.                     Catch ex As Exception
  361.                         Message = ex.Message
  362.                     End Try
  363.                 End If
  364.             End If
  365.             If PSSSendEmailConfirmation = True Or PSSSyncExchangeCalendar = True Then
  366.                 service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, tmpEmail)
  367.             End If
  368.             Try
  369.                 If InStr(tmpEmail, "@tfc.org") > 0 And PSSSyncExchangeCalendar = True Then
  370.                     'Create appointment object and set properties as required
  371.                     Dim appt As Appointment = New Appointment(service)
  372.                     appt.Subject = tmpEvtDescription & " - " & tmpPrtDescription
  373.                     'tmpBody = "Event: " & tmpEvtDescription & ", Part: " & tmpPrtDescription & ", Call Time: " & tmpCallTime & _
  374.                     '            ", Start Time: " & tmpStartTime & ", End Time: " & tmpEndTime & ", Out Time: " & tmpOutTime & ", Location: " & tmpLocDescription & _
  375.                     '            ", Position: " & tmpPosDescription & ", Type: " & tmpTypDescription & ", Status: " & tmpStDescription & ", Notes: " & tmpNotes
  376.                     tmpBody = "Position: " & tmpPosDescription & vbCrLf & "Notes: " & tmpNotes
  377.                     appt.Body = tmpBody
  378.                     appt.Location = tmpLocDescription
  379.                     appt.Start = tmpSchDate & " " & tmpCallTime
  380.                     If tmpOutTime = Nothing Then
  381.                         appt.End = tmpSchDate & " " & tmpStartTime.AddHours(1)
  382.                     Else
  383.                         appt.End = tmpSchDate & " " & tmpOutTime
  384.                     End If
  385.                     appt.IsReminderSet = False
  386.                     'find and delete entry
  387.                     Dim findResults As FindItemsResults(Of Appointment) = service.FindAppointments(WellKnownFolderName.Calendar, New CalendarView(tmpSchDate, tmpSchDate.AddHours(24)))
  388.                     Dim items As New List(Of Item)()
  389.                     For Each appointment As Appointment In findResults
  390.                         items.Add(appointment)
  391.                     Next
  392.                     If items.Count <> 0 Then
  393.                         service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties)
  394.                         For Each Appointment As Appointment In items
  395.                             If Not Appointment.IsCancelled Then
  396.                                 If Appointment.Subject = tmpEvtDescription & " - " & tmpPrtDescription Or Appointment.Subject = tmpEvtDescription Then
  397.                                     Appointment.Delete(DeleteMode.HardDelete)
  398.                                     Message = "Old EWS Appointment deleted from Outlook calendar."
  399.                                 End If
  400.                             End If
  401.                         Next
  402.                     End If
  403.                 End If
  404.             Catch ex As Exception
  405.                 Message = ex.Message
  406.             End Try
  407.  
  408.  
  409.             'add new entry
  410.             tmpSchDate = tmpRsNew("schDate")
  411.             tmpEvtDescription = tlcsub.tlcGetEventDesc(tmpRsNew("schEvtID"))
  412.             tmpPrtDescription = tlcsub.tlcGetPartDesc(tmpRsNew("schPartsID"))
  413.             If Not IsDBNull(tmpRsNew("schCallTime")) Then
  414.                 tmpCallTime = Format(tmpRsNew("schCallTime"), "hh:mm:ss tt")
  415.             Else
  416.                 tmpCallTime = "12:00:00 AM"
  417.             End If
  418.             If Not IsDBNull(tmpRsNew("schStartTime")) Then
  419.                 tmpStartTime = Format(tmpRsNew("schStartTime"), "hh:mm:ss tt")
  420.             Else
  421.                 tmpStartTime = "12:00:00 AM"
  422.             End If
  423.             If Not IsDBNull(tmpRsNew("schEndTime")) Then
  424.                 tmpEndTime = Format(tmpRsNew("schEndTime"), "hh:mm:ss tt")
  425.             Else
  426.                 tmpEndTime = "12:00:00 AM"
  427.             End If
  428.             If Not IsDBNull(tmpRsNew("schOutTime")) Then
  429.                 tmpOutTime = Format(tmpRsNew("schOutTime"), "hh:mm:ss tt")
  430.             Else
  431.                 tmpOutTime = "12:00:00 AM"
  432.             End If
  433.             tmpLocDescription = tlcsub.tlcGetLocationName(tmpRsNew("schLocID"))
  434.             tmpPosDescription = tlcsub.tlcGetPositionName(tmpRsNew("schPosID"))
  435.             tmpTypDescription = tlcsub.tlcGetTypeDesc(tmpRsNew("schTypID"))
  436.             tmpEmpName = tlcsub.tlcGetEmployeeName(tmpRsNew("schEmpID"))
  437.             tmpNotes = tlcsub.SafeDBNull(tmpRsNew("schNotes"))
  438.             tmpEmail = tlcsub.tlcGetEmployeeEmail(tmpRsNew("schEmpID"))
  439.             'tmpEmail = ew_Session("tfpssnet_Status_UserEmail")
  440.             Select Case tmpRsNew("schStatus")
  441.                 Case 1
  442.                     tmpAction = "A"
  443.                     tmpStatus = "BUSY"
  444.                     tmpType = "C"
  445.                     tmpNewStatus = "Confirmed"
  446.                     tmpStDescription = "Confirmed"
  447.                 Case 2
  448.                     tmpAction = "D"
  449.                     tmpType = "U"
  450.                     tmpNewStatus = "Un-confirmed"
  451.                     tmpStDescription = "Un-confirmed"
  452.                 Case 3
  453.                     tmpAction = "D"
  454.                     tmpType = "X"
  455.                     tmpNewStatus = "Cannot Work"
  456.                     tmpStDescription = "Cannot Work"
  457.                 Case 4
  458.                     tmpAction = "A"
  459.                     tmpStatus = "TENTATIVE"
  460.                     tmpType = "T"
  461.                     tmpNewStatus = "Tentative"
  462.                     tmpStDescription = "Tentative"
  463.             End Select
  464.  
  465.             If tmpNewStatus = "Confirmed" Or tmpNewStatus = "Tentative" Then
  466.                 If PSSSendEmailConfirmation = True Or PSSSyncExchangeCalendar = True Then
  467.                     service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, tmpEmail)
  468.                 End If
  469.                 Try
  470.                     If InStr(tmpEmail, "@tfc.org") > 0 And PSSSyncExchangeCalendar = True Then
  471.                         'Create appointment object and set properties as required
  472.                         Dim appt As Appointment = New Appointment(service)
  473.                         appt.Subject = tmpEvtDescription & " - " & tmpPrtDescription
  474.                         'tmpBody = "Event: " & tmpEvtDescription & ", Part: " & tmpPrtDescription & ", Call Time: " & tmpCallTime & _
  475.                         '            ", Start Time: " & tmpStartTime & ", End Time: " & tmpEndTime & ", Out Time: " & tmpOutTime & ", Location: " & tmpLocDescription & _
  476.                         '            ", Position: " & tmpPosDescription & ", Type: " & tmpTypDescription & ", Status: " & tmpStDescription & ", Notes: " & tmpNotes
  477.                         tmpBody = "Position: " & tmpPosDescription & vbCrLf & "Notes: " & tmpNotes
  478.                         appt.Body = tmpBody
  479.                         appt.Location = tmpLocDescription
  480.                         appt.Start = tmpSchDate & " " & tmpCallTime
  481.                         If tmpOutTime = Nothing Then
  482.                             appt.End = tmpSchDate & " " & tmpStartTime.AddHours(1)
  483.                         Else
  484.                             appt.End = tmpSchDate & " " & tmpOutTime
  485.                         End If
  486.                         appt.IsReminderSet = False
  487.                         'find and delete entry
  488.                         Dim findResults As FindItemsResults(Of Appointment) = service.FindAppointments(WellKnownFolderName.Calendar, New CalendarView(tmpSchDate, tmpSchDate.AddHours(24)))
  489.                         Dim items As New List(Of Item)()
  490.                         For Each appointment As Appointment In findResults
  491.                             items.Add(appointment)
  492.                         Next
  493.                         'If items.Count <> 0 Then
  494.                         '    service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties)
  495.                         '    For Each Appointment As Appointment In items
  496.                         '        If Not Appointment.IsCancelled Then
  497.                         '            If Appointment.Subject = tmpEvtDescription or Appointment.Subject = tmpEvtDescription Then
  498.                         '                Appointment.Delete(DeleteMode.HardDelete)
  499.                         '                Message = "Old EWS Appointment deleted from Outlook calendar."
  500.                         '            End If
  501.                         '        End If
  502.                         '    Next
  503.                         'End If
  504.                         If tmpNewStatus = "Tentative" Then
  505.                             appt.LegacyFreeBusyStatus = LegacyFreeBusyStatus.Tentative
  506.                         End If
  507.                         appt.Save(WellKnownFolderName.Calendar, SendInvitationsMode.SendToNone)
  508.                         Message = "New EWS Appointment added to Outlook calendar."
  509.                     End If
  510.                 Catch ex As Exception
  511.                     Message = ex.Message
  512.                 End Try
  513.             End If
  514.         End Sub
  515.  
  516.         Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
  517.             'Return True to force the certificate to be accepted.
  518.             Return True
  519.         End Function
  520.  
  521.         Private Shared Function RedirectionUrlValaditionCallBack(ByVal redirectionURL As String) As Boolean
  522.             Dim result As Boolean = False
  523.             Dim redirectionuri As New Uri(redirectionURL)
  524.             If redirectionuri.Scheme = "https" Then
  525.                 result = True
  526.             End If
  527.             Return result
  528.         End Function
  529.  
  530.         '
  531.         ' Get upload file
  532.         '
  533.         Sub GetUploadFiles()
  534.  
  535.             ' Get upload data
  536.         End Sub
  537.  
  538.         '
  539.         ' Load default values
  540.         '
  541.         Sub LoadDefaultValues()
  542.         End Sub
  543.  
  544.         '
  545.         ' Load form values
  546.         '
  547.         Sub LoadFormValues()
  548.             tblSchedule.schDate.FormValue = ObjForm.GetValue("x_schDate")
  549.             tblSchedule.schDate.CurrentValue = ew_UnFormatDateTime(tblSchedule.schDate.CurrentValue, 6)
  550.             tblSchedule.schDate.OldValue = ObjForm.GetValue("o_schDate")
  551.             tblSchedule.schEvtID.FormValue = ObjForm.GetValue("x_schEvtID")
  552.             tblSchedule.schEvtID.OldValue = ObjForm.GetValue("o_schEvtID")
  553.             tblSchedule.schPartsID.FormValue = ObjForm.GetValue("x_schPartsID")
  554.             tblSchedule.schPartsID.OldValue = ObjForm.GetValue("o_schPartsID")
  555.             tblSchedule.schCallTime.FormValue = ObjForm.GetValue("x_schCallTime")
  556.             tblSchedule.schCallTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schCallTime.CurrentValue, 4)
  557.             tblSchedule.schCallTime.OldValue = ObjForm.GetValue("o_schCallTime")
  558.             tblSchedule.schStartTime.FormValue = ObjForm.GetValue("x_schStartTime")
  559.             tblSchedule.schStartTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schStartTime.CurrentValue, 4)
  560.             tblSchedule.schStartTime.OldValue = ObjForm.GetValue("o_schStartTime")
  561.             tblSchedule.schEndTime.FormValue = ObjForm.GetValue("x_schEndTime")
  562.             tblSchedule.schEndTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schEndTime.CurrentValue, 4)
  563.             tblSchedule.schEndTime.OldValue = ObjForm.GetValue("o_schEndTime")
  564.             tblSchedule.schOutTime.FormValue = ObjForm.GetValue("x_schOutTime")
  565.             tblSchedule.schOutTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schOutTime.CurrentValue, 4)
  566.             tblSchedule.schOutTime.OldValue = ObjForm.GetValue("o_schOutTime")
  567.             tblSchedule.schLocID.FormValue = ObjForm.GetValue("x_schLocID")
  568.             tblSchedule.schLocID.OldValue = ObjForm.GetValue("o_schLocID")
  569.             tblSchedule.schEmpID.FormValue = ObjForm.GetValue("x_schEmpID")
  570.             tblSchedule.schEmpID.OldValue = ObjForm.GetValue("o_schEmpID")
  571.             tblSchedule.schPosID.FormValue = ObjForm.GetValue("x_schPosID")
  572.             tblSchedule.schPosID.OldValue = ObjForm.GetValue("o_schPosID")
  573.             tblSchedule.schTypID.FormValue = ObjForm.GetValue("x_schTypID")
  574.             tblSchedule.schTypID.OldValue = ObjForm.GetValue("o_schTypID")
  575.             tblSchedule.schDepID.FormValue = ObjForm.GetValue("x_schDepID")
  576.             tblSchedule.schDepID.OldValue = ObjForm.GetValue("o_schDepID")
  577.             tblSchedule.schNotes.FormValue = ObjForm.GetValue("x_schNotes")
  578.             tblSchedule.schNotes.OldValue = ObjForm.GetValue("o_schNotes")
  579.             tblSchedule.schRate.FormValue = ObjForm.GetValue("x_schRate")
  580.             tblSchedule.schRate.OldValue = ObjForm.GetValue("o_schRate")
  581.             tblSchedule.schActualStart.FormValue = ObjForm.GetValue("x_schActualStart")
  582.             tblSchedule.schActualStart.CurrentValue = ew_UnFormatDateTime(tblSchedule.schActualStart.CurrentValue, 4)
  583.             tblSchedule.schActualStart.OldValue = ObjForm.GetValue("o_schActualStart")
  584.             tblSchedule.schActualEnd.FormValue = ObjForm.GetValue("x_schActualEnd")
  585.             tblSchedule.schActualEnd.CurrentValue = ew_UnFormatDateTime(tblSchedule.schActualEnd.CurrentValue, 4)
  586.             tblSchedule.schActualEnd.OldValue = ObjForm.GetValue("o_schActualEnd")
  587.             tblSchedule.schDateCreated.FormValue = ObjForm.GetValue("x_schDateCreated")
  588.             tblSchedule.schDateCreated.CurrentValue = ew_UnFormatDateTime(tblSchedule.schDateCreated.CurrentValue, 4)
  589.             tblSchedule.schDateCreated.OldValue = ObjForm.GetValue("o_schDateCreated")
  590.             tblSchedule.schDoubleBooked.FormValue = ObjForm.GetValue("x_schDoubleBooked")
  591.             tblSchedule.schDoubleBooked.OldValue = ObjForm.GetValue("o_schDoubleBooked")
  592.             tblSchedule.schStatus.FormValue = ObjForm.GetValue("x_schStatus")
  593.             tblSchedule.schStatus.OldValue = ObjForm.GetValue("o_schStatus")
  594.             tblSchedule.schDayOfWeek.FormValue = ObjForm.GetValue("x_schDayOfWeek")
  595.             tblSchedule.schDayOfWeek.OldValue = ObjForm.GetValue("o_schDayOfWeek")
  596.             tblSchedule.schSchID.FormValue = ObjForm.GetValue("x_schSchID")
  597.         End Sub
  598.  
  599.         '
  600.         ' Restore form values
  601.         '
  602.         Sub RestoreFormValues()
  603.             tblSchedule.schDate.CurrentValue = tblSchedule.schDate.FormValue
  604.             tblSchedule.schDate.CurrentValue = ew_UnFormatDateTime(tblSchedule.schDate.CurrentValue, 6)
  605.             tblSchedule.schEvtID.CurrentValue = tblSchedule.schEvtID.FormValue
  606.             tblSchedule.schPartsID.CurrentValue = tblSchedule.schPartsID.FormValue
  607.             tblSchedule.schCallTime.CurrentValue = tblSchedule.schCallTime.FormValue
  608.             tblSchedule.schCallTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schCallTime.CurrentValue, 4)
  609.             tblSchedule.schStartTime.CurrentValue = tblSchedule.schStartTime.FormValue
  610.             tblSchedule.schStartTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schStartTime.CurrentValue, 4)
  611.             tblSchedule.schEndTime.CurrentValue = tblSchedule.schEndTime.FormValue
  612.             tblSchedule.schEndTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schEndTime.CurrentValue, 4)
  613.             tblSchedule.schOutTime.CurrentValue = tblSchedule.schOutTime.FormValue
  614.             tblSchedule.schOutTime.CurrentValue = ew_UnFormatDateTime(tblSchedule.schOutTime.CurrentValue, 4)
  615.             tblSchedule.schLocID.CurrentValue = tblSchedule.schLocID.FormValue
  616.             tblSchedule.schEmpID.CurrentValue = tblSchedule.schEmpID.FormValue
  617.             tblSchedule.schPosID.CurrentValue = tblSchedule.schPosID.FormValue
  618.             tblSchedule.schTypID.CurrentValue = tblSchedule.schTypID.FormValue
  619.             tblSchedule.schDepID.CurrentValue = tblSchedule.schDepID.FormValue
  620.             tblSchedule.schNotes.CurrentValue = tblSchedule.schNotes.FormValue
  621.             tblSchedule.schRate.CurrentValue = tblSchedule.schRate.FormValue
  622.             tblSchedule.schActualStart.CurrentValue = tblSchedule.schActualStart.FormValue
  623.             tblSchedule.schActualStart.CurrentValue = ew_UnFormatDateTime(tblSchedule.schActualStart.CurrentValue, 4)
  624.             tblSchedule.schActualEnd.CurrentValue = tblSchedule.schActualEnd.FormValue
  625.             tblSchedule.schActualEnd.CurrentValue = ew_UnFormatDateTime(tblSchedule.schActualEnd.CurrentValue, 4)
  626.             tblSchedule.schDateCreated.CurrentValue = tblSchedule.schDateCreated.FormValue
  627.             tblSchedule.schDateCreated.CurrentValue = ew_UnFormatDateTime(tblSchedule.schDateCreated.CurrentValue, 6)
  628.             tblSchedule.schDoubleBooked.CurrentValue = tblSchedule.schDoubleBooked.FormValue
  629.             tblSchedule.schStatus.CurrentValue = tblSchedule.schStatus.FormValue
  630.             tblSchedule.schDayOfWeek.CurrentValue = tblSchedule.schDayOfWeek.FormValue
  631.             tblSchedule.schSchID.CurrentValue = tblSchedule.schSchID.FormValue
  632.         End Sub
  633.  
  634.         '
  635.         ' Load row based on key values
  636.         '
  637.         Function LoadRow() As Boolean
  638.             Dim RsRow As OleDbDataReader
  639.             Dim sFilter As String = tblSchedule.KeyFilter
  640.  
  641.             ' Row Selecting event
  642.             tblSchedule.Row_Selecting(sFilter)
  643.  
  644.             ' Load SQL based on filter
  645.             tblSchedule.CurrentFilter = sFilter
  646.             Dim sSql As String = tblSchedule.SQL
  647.  
  648.             ' Write SQL for debug
  649.             If EW_DEBUG_ENABLED Then ew_Write(sSql)
  650.             Try
  651.                 RsRow = Conn.GetTempDataReader(sSql)
  652.                 If Not RsRow.Read() Then
  653.                     Return False
  654.                 Else
  655.                     LoadRowValues(RsRow) ' Load row values
  656.  
  657.                     ' Row Selected event
  658.                     tblSchedule.Row_Selected(RsRow)
  659.                     Return True
  660.                 End If
  661.             Catch
  662.                 If EW_DEBUG_ENABLED Then Throw
  663.                 Return False
  664.             Finally
  665.                 Conn.CloseTempDataReader()
  666.             End Try
  667.         End Function
  668.  
  669.         '
  670.         ' Load row values from recordset
  671.         '
  672.         Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  673.             tblSchedule.schSchID.DbValue = RsRow("schSchID")
  674.             tblSchedule.schDate.DbValue = RsRow("schDate")
  675.             tblSchedule.schEvtID.DbValue = RsRow("schEvtID")
  676.             tblSchedule.schPartsID.DbValue = RsRow("schPartsID")
  677.             tblSchedule.schCallTime.DbValue = RsRow("schCallTime")
  678.             tblSchedule.schStartTime.DbValue = RsRow("schStartTime")
  679.             tblSchedule.schEndTime.DbValue = RsRow("schEndTime")
  680.             tblSchedule.schOutTime.DbValue = RsRow("schOutTime")
  681.             tblSchedule.schLocID.DbValue = RsRow("schLocID")
  682.             tblSchedule.schEmpID.DbValue = RsRow("schEmpID")
  683.             tblSchedule.schPosID.DbValue = RsRow("schPosID")
  684.             tblSchedule.schTypID.DbValue = RsRow("schTypID")
  685.             tblSchedule.schDepID.DbValue = RsRow("schDepID")
  686.             tblSchedule.schNotes.DbValue = RsRow("schNotes")
  687.             tblSchedule.schRate.DbValue = RsRow("schRate")
  688.             tblSchedule.schActualStart.DbValue = RsRow("schActualStart")
  689.             tblSchedule.schActualEnd.DbValue = RsRow("schActualEnd")
  690.             tblSchedule.schDateCreated.DbValue = RsRow("schDateCreated")
  691.             tblSchedule.schDoubleBooked.DbValue = IIf(ew_ConvertToBool(RsRow("schDoubleBooked")), "1", "0")
  692.             tblSchedule.schStatus.DbValue = RsRow("schStatus")
  693.             tblSchedule.schDayOfWeek.DbValue = RsRow("schDayOfWeek")
  694.         End Sub
  695.  
  696.         '
  697.         ' Render row values based on field settings
  698.         '
  699.         Sub RenderRow()
  700.  
  701.             ' Row Rendering event
  702.             tblSchedule.Row_Rendering()
  703.  
  704.             '
  705.             '  Common render codes for all row types
  706.             '
  707.             ' schDate
  708.  
  709.             tblSchedule.schDate.CellCssStyle = ""
  710.             tblSchedule.schDate.CellCssClass = ""
  711.  
  712.             ' schEvtID
  713.             tblSchedule.schEvtID.CellCssStyle = ""
  714.             tblSchedule.schEvtID.CellCssClass = ""
  715.  
  716.             ' schPartsID
  717.             tblSchedule.schPartsID.CellCssStyle = ""
  718.             tblSchedule.schPartsID.CellCssClass = ""
  719.  
  720.             ' schCallTime
  721.             tblSchedule.schCallTime.CellCssStyle = ""
  722.             tblSchedule.schCallTime.CellCssClass = ""
  723.  
  724.             ' schStartTime
  725.             tblSchedule.schStartTime.CellCssStyle = ""
  726.             tblSchedule.schStartTime.CellCssClass = ""
  727.  
  728.             ' schEndTime
  729.             tblSchedule.schEndTime.CellCssStyle = ""
  730.             tblSchedule.schEndTime.CellCssClass = ""
  731.  
  732.             ' schOutTime
  733.             tblSchedule.schOutTime.CellCssStyle = ""
  734.             tblSchedule.schOutTime.CellCssClass = ""
  735.  
  736.             ' schLocID
  737.             tblSchedule.schLocID.CellCssStyle = ""
  738.             tblSchedule.schLocID.CellCssClass = ""
  739.  
  740.             ' schEmpID
  741.             tblSchedule.schEmpID.CellCssStyle = ""
  742.             tblSchedule.schEmpID.CellCssClass = ""
  743.  
  744.             ' schPosID
  745.             tblSchedule.schPosID.CellCssStyle = ""
  746.             tblSchedule.schPosID.CellCssClass = ""
  747.  
  748.             ' schTypID
  749.             tblSchedule.schTypID.CellCssStyle = ""
  750.             tblSchedule.schTypID.CellCssClass = ""
  751.  
  752.             ' schDepID
  753.             tblSchedule.schDepID.CellCssStyle = ""
  754.             tblSchedule.schDepID.CellCssClass = ""
  755.  
  756.             ' schNotes
  757.             tblSchedule.schNotes.CellCssStyle = ""
  758.             tblSchedule.schNotes.CellCssClass = ""
  759.  
  760.             ' schRate
  761.             tblSchedule.schRate.CellCssStyle = ""
  762.             tblSchedule.schRate.CellCssClass = ""
  763.  
  764.             ' schActualStart
  765.             tblSchedule.schActualStart.CellCssStyle = ""
  766.             tblSchedule.schActualStart.CellCssClass = ""
  767.  
  768.             ' schActualEnd
  769.             tblSchedule.schActualEnd.CellCssStyle = ""
  770.             tblSchedule.schActualEnd.CellCssClass = ""
  771.  
  772.             ' schDateCreated
  773.             tblSchedule.schDateCreated.CellCssStyle = ""
  774.             tblSchedule.schDateCreated.CellCssClass = ""
  775.  
  776.             ' schDoubleBooked
  777.             tblSchedule.schDoubleBooked.CellCssStyle = ""
  778.             tblSchedule.schDoubleBooked.CellCssClass = ""
  779.  
  780.             ' schStatus
  781.             tblSchedule.schStatus.CellCssStyle = ""
  782.             tblSchedule.schStatus.CellCssClass = ""
  783.  
  784.             ' schDayOfWeek
  785.             tblSchedule.schDayOfWeek.CellCssStyle = ""
  786.             tblSchedule.schDayOfWeek.CellCssClass = ""
  787.  
  788.             '
  789.             '  View  Row
  790.             '
  791.  
  792.             If tblSchedule.RowType = EW_ROWTYPE_VIEW Then ' View row
  793.  
  794.                 ' schDate
  795.                 tblSchedule.schDate.ViewValue = tblSchedule.schDate.CurrentValue
  796.                 tblSchedule.schDate.ViewValue = ew_FormatDateTime(tblSchedule.schDate.ViewValue, 6)
  797.                 tblSchedule.schDate.CssStyle = ""
  798.                 tblSchedule.schDate.CssClass = ""
  799.                 tblSchedule.schDate.ViewCustomAttributes = ""
  800.  
  801.                 ' schEvtID
  802.                 If ew_NotEmpty(tblSchedule.schEvtID.CurrentValue) Then
  803.                     sSqlWrk = "SELECT [evtDescription] FROM [tblEvents] WHERE [evtID] = " & ew_AdjustSql(tblSchedule.schEvtID.CurrentValue) & " AND [evtIsActive]=True"
  804.                     sSqlWrk = sSqlWrk & " ORDER BY [evtDescription] "
  805.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  806.                     If RsWrk.Read() Then
  807.                         tblSchedule.schEvtID.ViewValue = RsWrk("evtDescription")
  808.                     Else
  809.                         tblSchedule.schEvtID.ViewValue = tblSchedule.schEvtID.CurrentValue
  810.                     End If
  811.                     Conn.CloseTempDataReader()
  812.                 Else
  813.                     tblSchedule.schEvtID.ViewValue = System.DBNull.Value
  814.                 End If
  815.                 tblSchedule.schEvtID.CssStyle = ""
  816.                 tblSchedule.schEvtID.CssClass = ""
  817.                 tblSchedule.schEvtID.ViewCustomAttributes = ""
  818.  
  819.                 ' schPartsID
  820.                 If ew_NotEmpty(tblSchedule.schPartsID.CurrentValue) Then
  821.                     sSqlWrk = "SELECT [prtDescription] FROM [tblParts] WHERE [prtID] = " & ew_AdjustSql(tblSchedule.schPartsID.CurrentValue) & " AND [prtIsActive]=True"
  822.                     sSqlWrk = sSqlWrk & " ORDER BY [prtDescription] "
  823.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  824.                     If RsWrk.Read() Then
  825.                         tblSchedule.schPartsID.ViewValue = RsWrk("prtDescription")
  826.                     Else
  827.                         tblSchedule.schPartsID.ViewValue = tblSchedule.schPartsID.CurrentValue
  828.                     End If
  829.                     Conn.CloseTempDataReader()
  830.                 Else
  831.                     tblSchedule.schPartsID.ViewValue = System.DBNull.Value
  832.                 End If
  833.                 tblSchedule.schPartsID.CssStyle = ""
  834.                 tblSchedule.schPartsID.CssClass = ""
  835.                 tblSchedule.schPartsID.ViewCustomAttributes = ""
  836.  
  837.                 ' schCallTime
  838.                 tblSchedule.schCallTime.ViewValue = tblSchedule.schCallTime.CurrentValue
  839.                 tblSchedule.schCallTime.ViewValue = ew_FormatDateTime(tblSchedule.schCallTime.ViewValue, 14)
  840.                 tblSchedule.schCallTime.CssStyle = ""
  841.                 tblSchedule.schCallTime.CssClass = ""
  842.                 tblSchedule.schCallTime.ViewCustomAttributes = ""
  843.  
  844.                 ' schStartTime
  845.                 tblSchedule.schStartTime.ViewValue = tblSchedule.schStartTime.CurrentValue
  846.                 tblSchedule.schStartTime.ViewValue = ew_FormatDateTime(tblSchedule.schStartTime.ViewValue, 14)
  847.                 tblSchedule.schStartTime.CssStyle = ""
  848.                 tblSchedule.schStartTime.CssClass = ""
  849.                 tblSchedule.schStartTime.ViewCustomAttributes = ""
  850.  
  851.                 ' schEndTime
  852.                 tblSchedule.schEndTime.ViewValue = tblSchedule.schEndTime.CurrentValue
  853.                 tblSchedule.schEndTime.ViewValue = ew_FormatDateTime(tblSchedule.schEndTime.ViewValue, 14)
  854.                 tblSchedule.schEndTime.CssStyle = ""
  855.                 tblSchedule.schEndTime.CssClass = ""
  856.                 tblSchedule.schEndTime.ViewCustomAttributes = ""
  857.  
  858.                 ' schOutTime
  859.                 tblSchedule.schOutTime.ViewValue = tblSchedule.schOutTime.CurrentValue
  860.                 tblSchedule.schOutTime.ViewValue = ew_FormatDateTime(tblSchedule.schOutTime.ViewValue, 14)
  861.                 tblSchedule.schOutTime.CssStyle = ""
  862.                 tblSchedule.schOutTime.CssClass = ""
  863.                 tblSchedule.schOutTime.ViewCustomAttributes = ""
  864.  
  865.                 ' schLocID
  866.                 If ew_NotEmpty(tblSchedule.schLocID.CurrentValue) Then
  867.                     sSqlWrk = "SELECT [locDescription] FROM [tblLocations] WHERE [locID] = " & ew_AdjustSql(tblSchedule.schLocID.CurrentValue) & " AND [locIsActive]=True"
  868.                     sSqlWrk = sSqlWrk & " ORDER BY [locDescription] "
  869.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  870.                     If RsWrk.Read() Then
  871.                         tblSchedule.schLocID.ViewValue = RsWrk("locDescription")
  872.                     Else
  873.                         tblSchedule.schLocID.ViewValue = tblSchedule.schLocID.CurrentValue
  874.                     End If
  875.                     Conn.CloseTempDataReader()
  876.                 Else
  877.                     tblSchedule.schLocID.ViewValue = System.DBNull.Value
  878.                 End If
  879.                 tblSchedule.schLocID.CssStyle = ""
  880.                 tblSchedule.schLocID.CssClass = ""
  881.                 tblSchedule.schLocID.ViewCustomAttributes = ""
  882.  
  883.                 ' schEmpID
  884.                 If ew_NotEmpty(tblSchedule.schEmpID.CurrentValue) Then
  885.                     sSqlWrk = "SELECT [empName] FROM [tblEmployees] WHERE [empID] = " & ew_AdjustSql(tblSchedule.schEmpID.CurrentValue) & " AND [empIsActive]=True"
  886.                     sSqlWrk = sSqlWrk & " ORDER BY [empFirstName] "
  887.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  888.                     If RsWrk.Read() Then
  889.                         tblSchedule.schEmpID.ViewValue = RsWrk("empName")
  890.                     Else
  891.                         tblSchedule.schEmpID.ViewValue = tblSchedule.schEmpID.CurrentValue
  892.                     End If
  893.                     Conn.CloseTempDataReader()
  894.                 Else
  895.                     tblSchedule.schEmpID.ViewValue = System.DBNull.Value
  896.                 End If
  897.                 tblSchedule.schEmpID.CssStyle = ""
  898.                 tblSchedule.schEmpID.CssClass = ""
  899.                 tblSchedule.schEmpID.ViewCustomAttributes = ""
  900.  
  901.                 ' schPosID
  902.                 If ew_NotEmpty(tblSchedule.schPosID.CurrentValue) Then
  903.                     sSqlWrk = "SELECT [posDescription] FROM [tblPositions] WHERE [posID] = " & ew_AdjustSql(tblSchedule.schPosID.CurrentValue) & " AND [posIsActive]=True"
  904.                     sSqlWrk = sSqlWrk & " ORDER BY [posDescription] "
  905.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  906.                     If RsWrk.Read() Then
  907.                         tblSchedule.schPosID.ViewValue = RsWrk("posDescription")
  908.                     Else
  909.                         tblSchedule.schPosID.ViewValue = tblSchedule.schPosID.CurrentValue
  910.                     End If
  911.                     Conn.CloseTempDataReader()
  912.                 Else
  913.                     tblSchedule.schPosID.ViewValue = System.DBNull.Value
  914.                 End If
  915.                 tblSchedule.schPosID.CssStyle = ""
  916.                 tblSchedule.schPosID.CssClass = ""
  917.                 tblSchedule.schPosID.ViewCustomAttributes = ""
  918.  
  919.                 ' schTypID
  920.                 If ew_NotEmpty(tblSchedule.schTypID.CurrentValue) Then
  921.                     sSqlWrk = "SELECT [typDescription] FROM [tblTypes] WHERE [typID] = " & ew_AdjustSql(tblSchedule.schTypID.CurrentValue) & " AND [typIsActive]=True"
  922.                     sSqlWrk = sSqlWrk & " ORDER BY [typDescription] "
  923.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  924.                     If RsWrk.Read() Then
  925.                         tblSchedule.schTypID.ViewValue = RsWrk("typDescription")
  926.                     Else
  927.                         tblSchedule.schTypID.ViewValue = tblSchedule.schTypID.CurrentValue
  928.                     End If
  929.                     Conn.CloseTempDataReader()
  930.                 Else
  931.                     tblSchedule.schTypID.ViewValue = System.DBNull.Value
  932.                 End If
  933.                 tblSchedule.schTypID.CssStyle = ""
  934.                 tblSchedule.schTypID.CssClass = ""
  935.                 tblSchedule.schTypID.ViewCustomAttributes = ""
  936.  
  937.                 ' schDepID
  938.                 If ew_NotEmpty(tblSchedule.schDepID.CurrentValue) Then
  939.                     sSqlWrk = "SELECT [depAcctCode], [depDescription] FROM [tblDepartments] WHERE [depID] = " & ew_AdjustSql(tblSchedule.schDepID.CurrentValue) & " AND [depIsActive]=True"
  940.                     sSqlWrk = sSqlWrk & " ORDER BY [depID] "
  941.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  942.                     If RsWrk.Read() Then
  943.                         tblSchedule.schDepID.ViewValue = RsWrk("depAcctCode")
  944.                         tblSchedule.schDepID.ViewValue = tblSchedule.schDepID.ViewValue & ew_ValueSeparator(0) & RsWrk("depDescription")
  945.                     Else
  946.                         tblSchedule.schDepID.ViewValue = tblSchedule.schDepID.CurrentValue
  947.                     End If
  948.                     Conn.CloseTempDataReader()
  949.                 Else
  950.                     tblSchedule.schDepID.ViewValue = System.DBNull.Value
  951.                 End If
  952.                 tblSchedule.schDepID.CssStyle = ""
  953.                 tblSchedule.schDepID.CssClass = ""
  954.                 tblSchedule.schDepID.ViewCustomAttributes = ""
  955.  
  956.                 ' schNotes
  957.                 tblSchedule.schNotes.ViewValue = tblSchedule.schNotes.CurrentValue
  958.                 tblSchedule.schNotes.CssStyle = ""
  959.                 tblSchedule.schNotes.CssClass = ""
  960.                 tblSchedule.schNotes.ViewCustomAttributes = ""
  961.  
  962.                 ' schRate
  963.                 tblSchedule.schRate.ViewValue = tblSchedule.schRate.CurrentValue
  964.                 tblSchedule.schRate.CssStyle = ""
  965.                 tblSchedule.schRate.CssClass = ""
  966.                 tblSchedule.schRate.ViewCustomAttributes = ""
  967.  
  968.                 ' schActualStart
  969.                 tblSchedule.schActualStart.ViewValue = tblSchedule.schActualStart.CurrentValue
  970.                 tblSchedule.schActualStart.ViewValue = ew_FormatDateTime(tblSchedule.schActualStart.ViewValue, 14)
  971.                 tblSchedule.schActualStart.CssStyle = ""
  972.                 tblSchedule.schActualStart.CssClass = ""
  973.                 tblSchedule.schActualStart.ViewCustomAttributes = ""
  974.  
  975.                 ' schActualEnd
  976.                 tblSchedule.schActualEnd.ViewValue = tblSchedule.schActualEnd.CurrentValue
  977.                 tblSchedule.schActualEnd.ViewValue = ew_FormatDateTime(tblSchedule.schActualEnd.ViewValue, 14)
  978.                 tblSchedule.schActualEnd.CssStyle = ""
  979.                 tblSchedule.schActualEnd.CssClass = ""
  980.                 tblSchedule.schActualEnd.ViewCustomAttributes = ""
  981.  
  982.                 ' schDateCreated
  983.                 tblSchedule.schDateCreated.ViewValue = tblSchedule.schDateCreated.CurrentValue
  984.                 tblSchedule.schDateCreated.ViewValue = ew_FormatDateTime(tblSchedule.schDateCreated.ViewValue, 4)
  985.                 tblSchedule.schDateCreated.CssStyle = ""
  986.                 tblSchedule.schDateCreated.CssClass = ""
  987.                 tblSchedule.schDateCreated.ViewCustomAttributes = ""
  988.  
  989.                 ' schDoubleBooked
  990.                 If Convert.ToString(tblSchedule.schDoubleBooked.CurrentValue) = "1" Then
  991.                     tblSchedule.schDoubleBooked.ViewValue = "Yes"
  992.                 Else
  993.                     tblSchedule.schDoubleBooked.ViewValue = "No"
  994.                 End If
  995.                 tblSchedule.schDoubleBooked.CssStyle = ""
  996.                 tblSchedule.schDoubleBooked.CssClass = ""
  997.                 tblSchedule.schDoubleBooked.ViewCustomAttributes = ""
  998.  
  999.                 ' schStatus
  1000.                 If ew_NotEmpty(tblSchedule.schStatus.CurrentValue) Then
  1001.                     sSqlWrk = "SELECT [stDescription] FROM [tblScheduleStatus] WHERE [stID] = " & ew_AdjustSql(tblSchedule.schStatus.CurrentValue) & " AND [stIsActive]=True"
  1002.                     sSqlWrk = sSqlWrk & " ORDER BY [stDescription] "
  1003.                     RsWrk = Conn.GetTempDataReader(sSqlWrk)
  1004.                     If RsWrk.Read() Then
  1005.                         tblSchedule.schStatus.ViewValue = RsWrk("stDescription")
  1006.                     Else
  1007.                         tblSchedule.schStatus.ViewValue = tblSchedule.schStatus.CurrentValue
  1008.                     End If
  1009.                     Conn.CloseTempDataReader()
  1010.                 Else
  1011.                     tblSchedule.schStatus.ViewValue = System.DBNull.Value
  1012.                 End If
  1013.                 tblSchedule.schStatus.CssStyle = ""
  1014.                 tblSchedule.schStatus.CssClass = ""
  1015.                 tblSchedule.schStatus.ViewCustomAttributes = ""
  1016.  
  1017.                 ' schDayOfWeek
  1018.                 If ew_NotEmpty(tblSchedule.schDayOfWeek.CurrentValue) Then
  1019.                     Select Case tblSchedule.schDayOfWeek.CurrentValue
  1020.                         Case "1"
  1021.                             tblSchedule.schDayOfWeek.ViewValue = "Sun"
  1022.                         Case "2"
  1023.                             tblSchedule.schDayOfWeek.ViewValue = "Mon"
  1024.                         Case "3"
  1025.                             tblSchedule.schDayOfWeek.ViewValue = "Tue"
  1026.                         Case "4"
  1027.                             tblSchedule.schDayOfWeek.ViewValue = "Wed"
  1028.                         Case "5"
  1029.                             tblSchedule.schDayOfWeek.ViewValue = "Thu"
  1030.                         Case "6"
  1031.                             tblSchedule.schDayOfWeek.ViewValue = "Fri"
  1032.                         Case "7"
  1033.                             tblSchedule.schDayOfWeek.ViewValue = "Sat"
  1034.                     End Select
  1035.                 Else
  1036.                     tblSchedule.schDayOfWeek.ViewValue = System.DBNull.Value
  1037.                 End If
  1038.                 tblSchedule.schDayOfWeek.CssStyle = ""
  1039.                 tblSchedule.schDayOfWeek.CssClass = ""
  1040.                 tblSchedule.schDayOfWeek.ViewCustomAttributes = ""
  1041.  
  1042.                 ' View refer script
  1043.                 ' schDate
  1044.  
  1045.                 tblSchedule.schDate.HrefValue = ""
  1046.  
  1047.                 ' schEvtID
  1048.                 tblSchedule.schEvtID.HrefValue = ""
  1049.  
  1050.                 ' schPartsID
  1051.                 tblSchedule.schPartsID.HrefValue = ""
  1052.  
  1053.                 ' schCallTime
  1054.                 tblSchedule.schCallTime.HrefValue = ""
  1055.  
  1056.                 ' schStartTime
  1057.                 tblSchedule.schStartTime.HrefValue = ""
  1058.  
  1059.                 ' schEndTime
  1060.                 tblSchedule.schEndTime.HrefValue = ""
  1061.  
  1062.                 ' schOutTime
  1063.                 tblSchedule.schOutTime.HrefValue = ""
  1064.  
  1065.                 ' schLocID
  1066.                 tblSchedule.schLocID.HrefValue = ""
  1067.  
  1068.                 ' schEmpID
  1069.                 tblSchedule.schEmpID.HrefValue = ""
  1070.  
  1071.                 ' schPosID
  1072.                 tblSchedule.schPosID.HrefValue = ""
  1073.  
  1074.                 ' schTypID
  1075.                 tblSchedule.schTypID.HrefValue = ""
  1076.  
  1077.                 ' schDepID
  1078.                 tblSchedule.schDepID.HrefValue = ""
  1079.  
  1080.                 ' schNotes
  1081.                 tblSchedule.schNotes.HrefValue = ""
  1082.  
  1083.                 ' schRate
  1084.                 tblSchedule.schRate.HrefValue = ""
  1085.  
  1086.                 ' schActualStart
  1087.                 tblSchedule.schActualStart.HrefValue = ""
  1088.  
  1089.                 ' schActualEnd
  1090.                 tblSchedule.schActualEnd.HrefValue = ""
  1091.  
  1092.                 ' schDateCreated
  1093.                 tblSchedule.schDateCreated.HrefValue = ""
  1094.  
  1095.                 ' schDoubleBooked
  1096.                 tblSchedule.schDoubleBooked.HrefValue = ""
  1097.  
  1098.                 ' schStatus
  1099.                 tblSchedule.schStatus.HrefValue = ""
  1100.  
  1101.                 ' schDayOfWeek
  1102.                 tblSchedule.schDayOfWeek.HrefValue = ""
  1103.  
  1104.                 '
  1105.                 '  Edit Row
  1106.                 '
  1107.  
  1108.             ElseIf tblSchedule.RowType = EW_ROWTYPE_EDIT Then ' Edit row
  1109.  
  1110.                 ' schDate
  1111.                 tblSchedule.schDate.EditCustomAttributes = ""
  1112.                 tblSchedule.schDate.EditValue = ew_FormatDateTime(tblSchedule.schDate.CurrentValue, 6)
  1113.  
  1114.                 ' schEvtID
  1115.                 tblSchedule.schEvtID.EditCustomAttributes = ""
  1116.                 sSqlWrk = "SELECT [evtID], [evtDescription], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblEvents]"
  1117.                 sWhereWrk = "[evtIsActive]=True"
  1118.                 If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1119.                 sSqlWrk = sSqlWrk & " ORDER BY [evtDescription] "
  1120.                 arwrk = Conn.GetRows(sSqlWrk)
  1121.                 arwrk.Insert(0, New Object() {"", "Please Select"})
  1122.                 tblSchedule.schEvtID.EditValue = arwrk
  1123.  
  1124.                 ' schPartsID
  1125.                 tblSchedule.schPartsID.EditCustomAttributes = ""
  1126.                 sSqlWrk = "SELECT [prtID], [prtDescription], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblParts]"
  1127.                 sWhereWrk = "[prtIsActive]=True"
  1128.                 If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1129.                 sSqlWrk = sSqlWrk & " ORDER BY [prtDescription] "
  1130.                 arwrk = Conn.GetRows(sSqlWrk)
  1131.                 arwrk.Insert(0, New Object() {"", "Please Select"})
  1132.                 tblSchedule.schPartsID.EditValue = arwrk
  1133.  
  1134.                 ' schCallTime
  1135.                 tblSchedule.schCallTime.EditCustomAttributes = ""
  1136.                 tblSchedule.schCallTime.EditValue = ew_FormatDateTime(tblSchedule.schCallTime.CurrentValue, 4)
  1137.  
  1138.                 ' schStartTime
  1139.                 tblSchedule.schStartTime.EditCustomAttributes = ""
  1140.                 tblSchedule.schStartTime.EditValue = ew_FormatDateTime(tblSchedule.schStartTime.CurrentValue, 4)
  1141.  
  1142.                 ' schEndTime
  1143.                 tblSchedule.schEndTime.EditCustomAttributes = ""
  1144.                 tblSchedule.schEndTime.EditValue = ew_FormatDateTime(tblSchedule.schEndTime.CurrentValue, 4)
  1145.  
  1146.                 ' schOutTime
  1147.                 tblSchedule.schOutTime.EditCustomAttributes = ""
  1148.                 tblSchedule.schOutTime.EditValue = ew_FormatDateTime(tblSchedule.schOutTime.CurrentValue, 4)
  1149.  
  1150.                 ' schLocID
  1151.                 tblSchedule.schLocID.EditCustomAttributes = ""
  1152.                 sSqlWrk = "SELECT [locID], [locDescription], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblLocations]"
  1153.                 sWhereWrk = "[locIsActive]=True"
  1154.                 If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1155.                 sSqlWrk = sSqlWrk & " ORDER BY [locDescription] "
  1156.                 arwrk = Conn.GetRows(sSqlWrk)
  1157.                 arwrk.Insert(0, New Object() {"", "Please Select"})
  1158.                 tblSchedule.schLocID.EditValue = arwrk
  1159.  
  1160.                 ' schEmpID
  1161.                 tblSchedule.schEmpID.EditCustomAttributes = ""
  1162.                 If Not Security.IsAdmin And Security.IsLoggedIn() Then ' Non system admin
  1163.                     tblSchedule.schEmpID.CurrentValue = Security.CurrentUserID
  1164.                     If ew_NotEmpty(tblSchedule.schEmpID.CurrentValue) Then
  1165.                         sSqlWrk = "SELECT [empName] FROM [tblEmployees] WHERE [empID] = " & ew_AdjustSql(tblSchedule.schEmpID.CurrentValue) & " AND [empIsActive]=True"
  1166.                         sSqlWrk = sSqlWrk & " ORDER BY [empFirstName] "
  1167.                         RsWrk = Conn.GetTempDataReader(sSqlWrk)
  1168.                         If RsWrk.Read() Then
  1169.                             tblSchedule.schEmpID.EditValue = RsWrk("empName")
  1170.                         Else
  1171.                             tblSchedule.schEmpID.EditValue = tblSchedule.schEmpID.CurrentValue
  1172.                         End If
  1173.                         Conn.CloseTempDataReader()
  1174.                     Else
  1175.                         tblSchedule.schEmpID.EditValue = System.DBNull.Value
  1176.                     End If
  1177.                     tblSchedule.schEmpID.CssStyle = ""
  1178.                     tblSchedule.schEmpID.CssClass = ""
  1179.                     tblSchedule.schEmpID.ViewCustomAttributes = ""
  1180.                 Else
  1181.                     sSqlWrk = "SELECT [empID], [empName], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblEmployees]"
  1182.                     sWhereWrk = "[empIsActive]=True"
  1183.                     sWhereWrk = tblEmployees.AddUserIDFilter(sWhereWrk)
  1184.                     If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1185.                     sSqlWrk = sSqlWrk & " ORDER BY [empFirstName] "
  1186.                     arwrk = Conn.GetRows(sSqlWrk)
  1187.                     arwrk.Insert(0, New Object() {"", "Please Select"})
  1188.                     tblSchedule.schEmpID.EditValue = arwrk
  1189.                 End If
  1190.  
  1191.                 ' schPosID
  1192.                 tblSchedule.schPosID.EditCustomAttributes = ""
  1193.                 sSqlWrk = "SELECT [posID], [posDescription], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblPositions]"
  1194.                 sWhereWrk = "[posIsActive]=True"
  1195.                 If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1196.                 sSqlWrk = sSqlWrk & " ORDER BY [posDescription] "
  1197.                 arwrk = Conn.GetRows(sSqlWrk)
  1198.                 arwrk.Insert(0, New Object() {"", "Please Select"})
  1199.                 tblSchedule.schPosID.EditValue = arwrk
  1200.  
  1201.                 ' schTypID
  1202.                 tblSchedule.schTypID.EditCustomAttributes = ""
  1203.                 sSqlWrk = "SELECT [typID], [typDescription], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblTypes]"
  1204.                 sWhereWrk = "[typIsActive]=True"
  1205.                 If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1206.                 sSqlWrk = sSqlWrk & " ORDER BY [typDescription] "
  1207.                 arwrk = Conn.GetRows(sSqlWrk)
  1208.                 arwrk.Insert(0, New Object() {"", "Please Select"})
  1209.                 tblSchedule.schTypID.EditValue = arwrk
  1210.  
  1211.                 ' schDepID
  1212.                 tblSchedule.schDepID.EditCustomAttributes = ""
  1213.                 sSqlWrk = "SELECT [depID], [depAcctCode], [depDescription], '' AS SelectFilterFld FROM [tblDepartments]"
  1214.                 sWhereWrk = "[depIsActive]=True"
  1215.                 If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1216.                 sSqlWrk = sSqlWrk & " ORDER BY [depID] "
  1217.                 arwrk = Conn.GetRows(sSqlWrk)
  1218.                 arwrk.Insert(0, New Object() {"", "Please Select", ""})
  1219.                 tblSchedule.schDepID.EditValue = arwrk
  1220.  
  1221.                 ' schNotes
  1222.                 tblSchedule.schNotes.EditCustomAttributes = ""
  1223.                 tblSchedule.schNotes.EditValue = ew_HtmlEncode(tblSchedule.schNotes.CurrentValue)
  1224.  
  1225.                 ' schRate
  1226.                 tblSchedule.schRate.EditCustomAttributes = ""
  1227.                 tblSchedule.schRate.EditValue = ew_HtmlEncode(tblSchedule.schRate.CurrentValue)
  1228.  
  1229.                 ' schActualStart
  1230.                 tblSchedule.schActualStart.EditCustomAttributes = ""
  1231.                 tblSchedule.schActualStart.EditValue = ew_FormatDateTime(tblSchedule.schActualStart.CurrentValue, 4)
  1232.  
  1233.                 ' schActualEnd
  1234.                 tblSchedule.schActualEnd.EditCustomAttributes = ""
  1235.                 tblSchedule.schActualEnd.EditValue = ew_FormatDateTime(tblSchedule.schActualEnd.CurrentValue, 4)
  1236.  
  1237.                 ' schDateCreated
  1238.                 ' schDoubleBooked
  1239.  
  1240.                 tblSchedule.schDoubleBooked.EditCustomAttributes = ""
  1241.  
  1242.                 ' schStatus
  1243.                 tblSchedule.schStatus.EditCustomAttributes = ""
  1244.                 sSqlWrk = "SELECT [stID], [stDescription], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblScheduleStatus]"
  1245.                 sWhereWrk = "[stIsActive]=True"
  1246.                 If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  1247.                 sSqlWrk = sSqlWrk & " ORDER BY [stDescription] "
  1248.                 arwrk = Conn.GetRows(sSqlWrk)
  1249.                 arwrk.Insert(0, New Object() {"", "Please Select"})
  1250.                 tblSchedule.schStatus.EditValue = arwrk
  1251.  
  1252.                 ' schDayOfWeek
  1253.                 tblSchedule.schDayOfWeek.EditCustomAttributes = ""
  1254.                 arwrk = New ArrayList
  1255.                 arwrk.Add(New String() {"1", "Sun"})
  1256.                 arwrk.Add(New String() {"2", "Mon"})
  1257.                 arwrk.Add(New String() {"3", "Tue"})
  1258.                 arwrk.Add(New String() {"4", "Wed"})
  1259.                 arwrk.Add(New String() {"5", "Thu"})
  1260.                 arwrk.Add(New String() {"6", "Fri"})
  1261.                 arwrk.Add(New String() {"7", "Sat"})
  1262.                 arwrk.Insert(0, New String() {"", "Please Select"})
  1263.                 tblSchedule.schDayOfWeek.EditValue = arwrk
  1264.  
  1265.                 ' Edit refer script
  1266.                 ' schDate
  1267.  
  1268.                 tblSchedule.schDate.HrefValue = ""
  1269.  
  1270.                 ' schEvtID
  1271.                 tblSchedule.schEvtID.HrefValue = ""
  1272.  
  1273.                 ' schPartsID
  1274.                 tblSchedule.schPartsID.HrefValue = ""
  1275.  
  1276.                 ' schCallTime
  1277.                 tblSchedule.schCallTime.HrefValue = ""
  1278.  
  1279.                 ' schStartTime
  1280.                 tblSchedule.schStartTime.HrefValue = ""
  1281.  
  1282.                 ' schEndTime
  1283.                 tblSchedule.schEndTime.HrefValue = ""
  1284.  
  1285.                 ' schOutTime
  1286.                 tblSchedule.schOutTime.HrefValue = ""
  1287.  
  1288.                 ' schLocID
  1289.                 tblSchedule.schLocID.HrefValue = ""
  1290.  
  1291.                 ' schEmpID
  1292.                 tblSchedule.schEmpID.HrefValue = ""
  1293.  
  1294.                 ' schPosID
  1295.                 tblSchedule.schPosID.HrefValue = ""
  1296.  
  1297.                 ' schTypID
  1298.                 tblSchedule.schTypID.HrefValue = ""
  1299.  
  1300.                 ' schDepID
  1301.                 tblSchedule.schDepID.HrefValue = ""
  1302.  
  1303.                 ' schNotes
  1304.                 tblSchedule.schNotes.HrefValue = ""
  1305.  
  1306.                 ' schRate
  1307.                 tblSchedule.schRate.HrefValue = ""
  1308.  
  1309.                 ' schActualStart
  1310.                 tblSchedule.schActualStart.HrefValue = ""
  1311.  
  1312.                 ' schActualEnd
  1313.                 tblSchedule.schActualEnd.HrefValue = ""
  1314.  
  1315.                 ' schDateCreated
  1316.                 tblSchedule.schDateCreated.HrefValue = ""
  1317.  
  1318.                 ' schDoubleBooked
  1319.                 tblSchedule.schDoubleBooked.HrefValue = ""
  1320.  
  1321.                 ' schStatus
  1322.                 tblSchedule.schStatus.HrefValue = ""
  1323.  
  1324.                 ' schDayOfWeek
  1325.                 tblSchedule.schDayOfWeek.HrefValue = ""
  1326.             End If
  1327.  
  1328.             ' Row Rendered event
  1329.             tblSchedule.Row_Rendered()
  1330.         End Sub
  1331.  
  1332.         '
  1333.         ' Validate form
  1334.         '
  1335.         Function ValidateForm() As Boolean
  1336.  
  1337.             ' Initialize
  1338.             ParentPage.gsFormError = ""
  1339.  
  1340.             ' Check if validation required
  1341.             'If Not EW_SERVER_VALIDATE Then Return (ParentPage.gsFormError = "")
  1342.             'If ew_Empty(tblSchedule.schDate.FormValue) Then
  1343.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1344.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Date"
  1345.             'End If
  1346.             'If Not ew_CheckUSDate(tblSchedule.schDate.FormValue) Then
  1347.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1348.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect date, format = mm/dd/yyyy - Date"
  1349.             'End If
  1350.             'If ew_Empty(tblSchedule.schEvtID.FormValue) Then
  1351.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1352.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Event"
  1353.             'End If
  1354.             'If ew_Empty(tblSchedule.schPartsID.FormValue) Then
  1355.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1356.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Part"
  1357.             'End If
  1358.  
  1359.             Dim tlc As New AspNetMaker7_tfpssnet
  1360.             If tblSchedule.schCallTime.FormValue <> "" Then tlc.tlcCheckTime(tblSchedule.schCallTime.FormValue)
  1361.             If tblSchedule.schStartTime.FormValue <> "" Then tlc.tlcCheckTime(tblSchedule.schStartTime.FormValue)
  1362.             If tblSchedule.schEndTime.FormValue <> "" Then tlc.tlcCheckTime(tblSchedule.schEndTime.FormValue)
  1363.             If tblSchedule.schOutTime.FormValue <> "" Then tlc.tlcCheckTime(tblSchedule.schOutTime.FormValue)
  1364.             If tblSchedule.schActualStart.FormValue <> "" Then tlc.tlcCheckTime(tblSchedule.schActualStart.FormValue)
  1365.             If tblSchedule.schActualEnd.FormValue <> "" Then tlc.tlcCheckTime(tblSchedule.schActualEnd.FormValue)
  1366.  
  1367.             If Not ew_CheckTime(tblSchedule.schCallTime.FormValue) And tblSchedule.schCallTime.FormValue <> "" Then
  1368.                 If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1369.                 ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - Call Time"
  1370.             End If
  1371.             If Not ew_CheckTime(tblSchedule.schStartTime.FormValue) And tblSchedule.schStartTime.FormValue <> "" Then
  1372.                 If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1373.                 ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - Start Time"
  1374.             End If
  1375.             If Not ew_CheckTime(tblSchedule.schEndTime.FormValue) And tblSchedule.schEndTime.FormValue <> "" Then
  1376.                 If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1377.                 ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - End Time"
  1378.             End If
  1379.             If Not ew_CheckTime(tblSchedule.schOutTime.FormValue) And tblSchedule.schOutTime.FormValue <> "" Then
  1380.                 If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1381.                 ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - Out Time"
  1382.             End If
  1383.             If Not ew_CheckTime(tblSchedule.schActualStart.FormValue) And tblSchedule.schActualStart.FormValue <> "" Then
  1384.                 If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1385.                 ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - Actual Start"
  1386.             End If
  1387.             If Not ew_CheckTime(tblSchedule.schActualEnd.FormValue) And tblSchedule.schActualEnd.FormValue <> "" Then
  1388.                 If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1389.                 ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - Actual End"
  1390.             End If
  1391.             'If ew_Empty(tblSchedule.schLocID.FormValue) Then
  1392.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1393.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Location"
  1394.             'End If
  1395.             'If ew_Empty(tblSchedule.schEmpID.FormValue) Then
  1396.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1397.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Employee"
  1398.             'End If
  1399.             'If ew_Empty(tblSchedule.schPosID.FormValue) Then
  1400.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1401.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Position"
  1402.             'End If
  1403.             'If ew_Empty(tblSchedule.schTypID.FormValue) Then
  1404.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1405.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Type"
  1406.             'End If
  1407.             'If ew_Empty(tblSchedule.schDepID.FormValue) Then
  1408.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1409.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Department"
  1410.             'End If
  1411.             'If Not ew_CheckNumber(tblSchedule.schRate.FormValue) Then
  1412.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1413.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect floating point number - Rate"
  1414.             'End If
  1415.             'If Not ew_CheckTime(tblSchedule.schActualStart.FormValue) Then
  1416.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1417.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - Actual Start"
  1418.             'End If
  1419.             'If Not ew_CheckTime(tblSchedule.schActualEnd.FormValue) Then
  1420.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1421.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect time (hh:mm:ss) - Actual End"
  1422.             'End If
  1423.             'If ew_Empty(tblSchedule.schStatus.FormValue) Then
  1424.             '    If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1425.             '    ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Status"
  1426.             'End If
  1427.  
  1428.             ' Return validate result
  1429.             Dim Valid As Boolean = (ParentPage.gsFormError = "")
  1430.  
  1431.             ' Form_CustomValidate event
  1432.             Dim sFormCustomError As String = ""
  1433.             Valid = Valid And Form_CustomValidate(sFormCustomError)
  1434.             If sFormCustomError <> "" Then
  1435.                 If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  1436.                 ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  1437.             End If
  1438.             Return Valid
  1439.         End Function
  1440.  
  1441.         '
  1442.         ' Update record based on key values
  1443.         '
  1444.         Function EditRow(ByRef tmpRsOld As OrderedDictionary, ByRef tmpRsNew As OrderedDictionary) As Boolean
  1445.             Dim RsEdit As OleDbDataReader, RsChk As OleDbDataReader
  1446.             Dim sSql As String, sFilter As String
  1447.             Dim sSqlChk As String, sFilterChk As String
  1448.             Dim bUpdateRow As Boolean
  1449.             Dim RsOld As OrderedDictionary
  1450.             Dim sIdxErrMsg As String
  1451.             Dim Rs As New OrderedDictionary
  1452.             Dim tlcsub As New AspNetMaker7_tfpssnet
  1453.             sFilter = tblSchedule.KeyFilter
  1454.             tblSchedule.CurrentFilter = sFilter
  1455.             sSql = tblSchedule.SQL
  1456.             Try
  1457.                 RsEdit = Conn.GetDataReader(sSql)
  1458.             Catch e As Exception
  1459.                 If EW_DEBUG_ENABLED Then Throw
  1460.                 Message = e.Message
  1461.                 RsEdit.Close()
  1462.                 EditRow = False
  1463.             End Try
  1464.             If Not RsEdit.Read() Then
  1465.                 RsEdit.Close()
  1466.                 EditRow = False ' Update Failed
  1467.             Else
  1468.                 RsOld = Conn.GetRow(RsEdit)
  1469.                 RsEdit.Close()
  1470.  
  1471.                 ' schDate
  1472.                 tblSchedule.schDate.SetDbValue(ew_UnFormatDateTime(tblSchedule.schDate.CurrentValue, 6), System.DBNull.Value)
  1473.                 Rs("schDate") = tblSchedule.schDate.DbValue
  1474.  
  1475.                 ' schEvtID
  1476.                 tblSchedule.schEvtID.SetDbValue(tblSchedule.schEvtID.CurrentValue, System.DBNull.Value)
  1477.                 Rs("schEvtID") = tblSchedule.schEvtID.DbValue
  1478.  
  1479.                 ' schPartsID
  1480.                 tblSchedule.schPartsID.SetDbValue(tblSchedule.schPartsID.CurrentValue, System.DBNull.Value)
  1481.                 Rs("schPartsID") = tblSchedule.schPartsID.DbValue
  1482.  
  1483.                 ' schCallTime
  1484.                 tblSchedule.schCallTime.SetDbValue(ew_UnFormatDateTime(tblSchedule.schCallTime.CurrentValue, 4), System.DBNull.Value)
  1485.                 Rs("schCallTime") = tblSchedule.schCallTime.DbValue
  1486.  
  1487.                 ' schStartTime
  1488.                 tblSchedule.schStartTime.SetDbValue(ew_UnFormatDateTime(tblSchedule.schStartTime.CurrentValue, 4), System.DBNull.Value)
  1489.                 Rs("schStartTime") = tblSchedule.schStartTime.DbValue
  1490.  
  1491.                 ' schEndTime
  1492.                 tblSchedule.schEndTime.SetDbValue(ew_UnFormatDateTime(tblSchedule.schEndTime.CurrentValue, 4), System.DBNull.Value)
  1493.                 Rs("schEndTime") = tblSchedule.schEndTime.DbValue
  1494.  
  1495.                 ' schOutTime
  1496.                 tblSchedule.schOutTime.SetDbValue(ew_UnFormatDateTime(tblSchedule.schOutTime.CurrentValue, 4), System.DBNull.Value)
  1497.                 Rs("schOutTime") = tblSchedule.schOutTime.DbValue
  1498.  
  1499.                 ' schLocID
  1500.                 tblSchedule.schLocID.SetDbValue(tblSchedule.schLocID.CurrentValue, System.DBNull.Value)
  1501.                 Rs("schLocID") = tblSchedule.schLocID.DbValue
  1502.  
  1503.                 ' schEmpID
  1504.                 tblSchedule.schEmpID.SetDbValue(tblSchedule.schEmpID.CurrentValue, System.DBNull.Value)
  1505.                 Rs("schEmpID") = tblSchedule.schEmpID.DbValue
  1506.  
  1507.                 ' schPosID
  1508.                 tblSchedule.schPosID.SetDbValue(tblSchedule.schPosID.CurrentValue, System.DBNull.Value)
  1509.                 Rs("schPosID") = tblSchedule.schPosID.DbValue
  1510.  
  1511.                 ' schTypID
  1512.                 tblSchedule.schTypID.SetDbValue(tblSchedule.schTypID.CurrentValue, System.DBNull.Value)
  1513.                 Rs("schTypID") = tblSchedule.schTypID.DbValue
  1514.  
  1515.                 ' schDepID
  1516.                 tblSchedule.schDepID.SetDbValue(tblSchedule.schDepID.CurrentValue, System.DBNull.Value)
  1517.                 Rs("schDepID") = tblSchedule.schDepID.DbValue
  1518.  
  1519.                 ' schNotes
  1520.                 tblSchedule.schNotes.SetDbValue(tblSchedule.schNotes.CurrentValue, System.DBNull.Value)
  1521.                 Rs("schNotes") = tblSchedule.schNotes.DbValue
  1522.  
  1523.                 ' schRate
  1524.                 tblSchedule.schRate.SetDbValue(tblSchedule.schRate.CurrentValue, System.DBNull.Value)
  1525.                 'Rs("schRate") = tblSchedule.schRate.DbValue
  1526.                 Rs("schRate") = tlcsub.tlcGetEmployeeRate(tblSchedule.schEmpID.DbValue)
  1527.  
  1528.                 ' schActualStart
  1529.                 tblSchedule.schActualStart.SetDbValue(ew_UnFormatDateTime(tblSchedule.schActualStart.CurrentValue, 4), System.DBNull.Value)
  1530.                 Rs("schActualStart") = tblSchedule.schActualStart.DbValue
  1531.  
  1532.                 ' schActualEnd
  1533.                 tblSchedule.schActualEnd.SetDbValue(ew_UnFormatDateTime(tblSchedule.schActualEnd.CurrentValue, 4), System.DBNull.Value)
  1534.                 Rs("schActualEnd") = tblSchedule.schActualEnd.DbValue
  1535.  
  1536.                 ' schDateCreated
  1537.                 tblSchedule.schDateCreated.DbValue = ew_CurrentDateTime()
  1538.                 Rs("schDateCreated") = tblSchedule.schDateCreated.DbValue
  1539.  
  1540.                 ' schDoubleBooked
  1541.                 tblSchedule.schDoubleBooked.SetDbValue((tblSchedule.schDoubleBooked.CurrentValue <> "" And Not IsDBNull(tblSchedule.schDoubleBooked.CurrentValue)), System.DBNull.Value)
  1542.                 Rs("schDoubleBooked") = tblSchedule.schDoubleBooked.DbValue
  1543.  
  1544.                 ' schStatus
  1545.                 tblSchedule.schStatus.SetDbValue(tblSchedule.schStatus.CurrentValue, System.DBNull.Value)
  1546.                 Rs("schStatus") = tblSchedule.schStatus.DbValue
  1547.  
  1548.                 ' schDayOfWeek
  1549.                 tblSchedule.schDayOfWeek.SetDbValue(tblSchedule.schDayOfWeek.CurrentValue, System.DBNull.Value)
  1550.                 'Rs("schDayOfWeek") = tblSchedule.schDayOfWeek.DbValue
  1551.                 Rs("schDayOfWeek") = Weekday(tblSchedule.schDate.DbValue)
  1552.  
  1553.                 ' Row Updating event
  1554.                 bUpdateRow = tblSchedule.Row_Updating(RsOld, Rs)
  1555.                 If bUpdateRow Then
  1556.                     Try
  1557.                         tblSchedule.Update(Rs)
  1558.                         EditRow = True
  1559.                     Catch e As Exception
  1560.                         If EW_DEBUG_ENABLED Then Throw
  1561.                         Message = e.Message
  1562.                         EditRow = False
  1563.                     End Try
  1564.                 Else
  1565.                     If tblSchedule.CancelMessage <> "" Then
  1566.                         Message = tblSchedule.CancelMessage
  1567.                         tblSchedule.CancelMessage = ""
  1568.                     Else
  1569.                         Message = "Update cancelled"
  1570.                     End If
  1571.                     EditRow = False
  1572.                 End If
  1573.             End If
  1574.  
  1575.             ' Row Updated event
  1576.             If EditRow Then
  1577.                 tblSchedule.Row_Updated(RsOld, Rs)
  1578.             End If
  1579.  
  1580.             tmpRsOld = RsOld
  1581.             tmpRsNew = Rs
  1582.  
  1583.         End Function
  1584.  
  1585.         ' Page Load event
  1586.         Public Sub Page_Load()
  1587.  
  1588.             'HttpContext.Current.Response.Write("Page Load")
  1589.         End Sub
  1590.  
  1591.         ' Page Unload event
  1592.         Public Sub Page_Unload()
  1593.  
  1594.             'HttpContext.Current.Response.Write("Page Unload")
  1595.         End Sub
  1596.  
  1597.         ' Form Custom Validate event
  1598.         Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  1599.  
  1600.             'Return error message in CustomError
  1601.             Return True
  1602.         End Function
  1603.     End Class
  1604.  
  1605.     '
  1606.     ' ASP.NET Page_Load event
  1607.     '
  1608.  
  1609.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  1610.         Response.Buffer = EW_RESPONSE_BUFFER
  1611.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  1612.  
  1613.         ' Page init
  1614.         tblSchedule_edit = New ctblSchedule_edit(Me)
  1615.         tblSchedule_edit.Page_Init()
  1616.  
  1617.         ' Page main processing
  1618.         tblSchedule_edit.Page_Main()
  1619.     End Sub
  1620.  
  1621.     '
  1622.     ' ASP.NET Page_Unload event
  1623.     '
  1624.  
  1625.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  1626.  
  1627.         ' Dispose page object
  1628.         If tblSchedule_edit IsNot Nothing Then tblSchedule_edit.Dispose()
  1629.     End Sub
  1630. End Class
  1631.