home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / iPhone / punchstatus2.aspx.vb < prev    next >
Text File  |  2014-12-14  |  17KB  |  271 lines

  1. ∩╗┐Imports System.Data.OleDb
  2. Imports System.Web
  3. Imports Microsoft.Exchange.WebServices.Data
  4. Imports System.Net
  5. Imports System.Net.Security
  6. Imports System.Security.Cryptography.X509Certificates
  7. Imports Microsoft.Exchange.WebServices.Autodiscover
  8.  
  9. Partial Class iPhoneNet_Default
  10.     Inherits AspNetMaker7_tfpssnet
  11.  
  12.     Public PSSSendEmailConfirmation As Boolean
  13.  
  14.     Public PSSSyncExchangeCalendar As Boolean
  15.  
  16.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  17.         Dim tlcsub As New AspNetMaker7_tfpssnet
  18.         PSSSendEmailConfirmation = tlcsub.tlcGetPSSEmailConfirmation()
  19.         PSSSyncExchangeCalendar = tlcsub.tlcGetPSSUpdateExchangeCalendar()
  20.  
  21.         'Dim service As New ExchangeService(requestedServerVersion:=ExchangeVersion.Exchange2010)
  22.         Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP1)
  23.  
  24.         Dim tmptype As String, tmpID As Integer, tmpEmail As String, tmpEvtDescription As String, tmpBody As String, tmpSchDate As Date, tmpEmpName As String
  25.         Dim tmpStatusDesc As String
  26.         Dim tmpPrtDescription As String, tmpLocDescription As String, tmpPosDescription As String, tmpTypDescription As String, tmpStDescription As String, tmpNotes As String
  27.  
  28.         tmptype = Request.QueryString("Type")
  29.         tmpID = Request.QueryString("ID")
  30.         If Not IsDBNull(tmpID) And Not IsDBNull(tmptype) Then
  31.             Dim rs1 As OleDbDataReader
  32.             Dim sSql As String, tmpMessage As String = "", tmpNewStatus As String = ""
  33.             sSql = "SELECT tblSchedule.*, tblEmployees.empName, tblEmployees.empEmail, tblEvents.evtDescription, tblParts.prtDescription, tblLocations.locDescription, tblPositions.posDescription, tblScheduleStatus.stDescription, " _
  34.     & "tblTypes.typDescription FROM tblTypes INNER JOIN (tblScheduleStatus INNER JOIN (tblPositions INNER JOIN (tblLocations INNER JOIN (tblParts INNER JOIN (tblEvents INNER JOIN (tblEmployees INNER JOIN " _
  35.     & "tblSchedule ON tblEmployees.empID = tblSchedule.schEmpID) ON tblEvents.evtID = tblSchedule.schEvtID) ON tblParts.prtID = tblSchedule.schPartsID) ON tblLocations.locID = tblSchedule.schLocID) ON " _
  36.     & "tblPositions.posID = tblSchedule.schPosID) ON tblScheduleStatus.stID = tblSchedule.schStatus) ON tblTypes.typID = tblSchedule.schTypID WHERE schSchID=" & tmpID
  37.             Conn = New cConnection()
  38.             rs1 = Conn.GetTempDataReader(sSql)
  39.             If rs1.Read() Then
  40.                 tmpMessage = Session("TFProduction_Status_UserID") & " changed event status from "
  41.                 Select Case rs1("schStatus")
  42.                     Case 1
  43.                         tmpMessage += "'Confirmed'"
  44.                     Case 2
  45.                         tmpMessage += "'Unconfirmed'"
  46.                     Case 3
  47.                         tmpMessage += "'Cannot Work'"
  48.                     Case 4
  49.                         tmpMessage += "'Tentative'"
  50.                 End Select
  51.                 tmpMessage += " to "
  52.                 Select Case tmptype
  53.                     Case "C"
  54.                         sSql = "UPDATE tblSchedule SET schStatus = 1 WHERE schSchID = " & tmpID
  55.                         tmpMessage += "'Confirmed'"
  56.                         tmpNewStatus = "Confirmed"
  57.                     Case "T"
  58.                         sSql = "UPDATE tblSchedule SET schStatus = 4 WHERE schSchID = " & tmpID
  59.                         tmpMessage += "'Tentative'"
  60.                         tmpNewStatus = "Tentative"
  61.                     Case "X"
  62.                         sSql = "UPDATE tblSchedule SET schStatus = 3 WHERE schSchID = " & tmpID
  63.                         tmpMessage += "'Cannot  Work'"
  64.                         tmpNewStatus = "Cannot Work"
  65.                     Case "U"
  66.                         sSql = "UPDATE tblSchedule SET schStatus = 2 WHERE schSchID = " & tmpID
  67.                         tmpMessage += "'Unconfirmed'"
  68.                         tmpNewStatus = "Unconfirmed"
  69.                 End Select
  70.                 tmpSchDate = FormatDateTime(rs1("schDate"), DateFormat.ShortDate)
  71.                 tmpEvtDescription = rs1("evtDescription")
  72.                 tmpEvtDescription = Replace(tmpEvtDescription, """", "")
  73.                 tmpPrtDescription = rs1("prtDescription")
  74.                 tmpLocDescription = rs1("locDescription")
  75.                 tmpPosDescription = rs1("posDescription")
  76.                 tmpStDescription = rs1("stDescription")
  77.                 tmpTypDescription = rs1("typDescription")
  78.                 tmpEmpName = rs1("empName")
  79.                 tmpEmail = rs1("empEmail")
  80.                 tmpStatusDesc = rs1("stDescription")
  81.                 tmpNotes = rs1("schNotes")
  82.  
  83.                 If PSSSendEmailConfirmation = True Or PSSSyncExchangeCalendar = True Then
  84.                     'Add a valid EWS service end point here or user Autodiscover
  85.                     'service.Url = New Uri("https://server14/ews/exchange.asmx")
  86.                     service.Url = New Uri("https://outlook.office365.com/EWS/Exchange.asmx")
  87.                     'Add a valid user credentials
  88.                     'service.Credentials = New WebCredentials("prodservices", "production88", "Business")
  89.                     service.Credentials = New WebCredentials("productionservices@tfc.org", "production88")
  90.                     service.AutodiscoverUrl("productionservices@tfc.org", AddressOf RedirectionUrlValaditionCallback)
  91.                     'To address the SSL challenge
  92.                     ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
  93.                 End If
  94.  
  95.                 If PSSSendEmailConfirmation = True Then
  96.                     tmpMessage += " for the following event:<br><br>"
  97.                     tmpMessage = tmpMessage & "<b>Employee:</b> " & tmpEmpName & "<br> "
  98.                     tmpMessage = tmpMessage & "<b>Date:</b> " & ew_FormatDateTime(rs1("schDate"), 2) & "<br> "
  99.                     tmpMessage = tmpMessage & "<b>Event:</b> " & rs1("evtDescription") & "<br> "
  100.                     tmpMessage = tmpMessage & "<b>Part:</b> " & rs1("prtDescription") & "<br>"
  101.                     tmpMessage = tmpMessage & "<b>Call Time:</b> " & ew_FormatDateTime(rs1("schCallTime"), 14) & "<br>"
  102.                     tmpMessage = tmpMessage & "<b>Start Time:</b> " & ew_FormatDateTime(rs1("schStartTime"), 14) & "<br>"
  103.                     tmpMessage = tmpMessage & "<b>End Time:</b> " & ew_FormatDateTime(rs1("schEndTime"), 14) & "<br>"
  104.                     tmpMessage = tmpMessage & "<b>Out Time:</b> " & ew_FormatDateTime(rs1("schOutTime"), 14) & "<br>"
  105.                     tmpMessage = tmpMessage & "<b>Location:</b> " & rs1("locDescription") & "<br>"
  106.                     tmpMessage = tmpMessage & "<b>Position:</b> " & rs1("posDescription") & "<br>"
  107.                     tmpMessage = tmpMessage & "<b>Status:</b> " & tmpNewStatus & "<br>"
  108.                     tmpMessage = tmpMessage & "<b>Type:</b> " & rs1("typDescription") & "<br><br>"
  109.                     tmpMessage = tmpMessage & "<b>Actual Start Time:</b> " & ew_FormatDateTime(rs1("schActualStart"), 14) & "<br>"
  110.                     tmpMessage = tmpMessage & "<b>Actual End Time:</b> " & ew_FormatDateTime(rs1("schActualEnd"), 14) & "<br><hr>"
  111.                     tmpMessage = tmpMessage & "sent from PSS iPhone/punchstatus."
  112.                     'ew_SendEmail("prodservices@tfchurch.org", "kirkmanton@tfchurch.org", "", "", "PSS Event status change for " & Session("TFProduction_Status_UserID"), tmpMessage, "html")
  113.                     Try
  114.                         'Create new message object and set properties required to send a mail
  115.                         Dim msg As EmailMessage = New EmailMessage(service)
  116.                         msg.Subject = "PSS Event status change by " & ew_Session("TFProduction_Status_UserName")
  117.                         msg.Body = tmpMessage
  118.                         'msg.ToRecipients.Add("tony.clayton@suddenlink.net")
  119.                         'msg.ToRecipients.Add("tonyc@tfchurch.org")
  120.                         msg.ToRecipients.Add("kirkmanton@tfc.org")
  121.                         msg.From = "productionservices@tfc.org"
  122.                         msg.SendAndSaveCopy()
  123.                         '                                            Message = "Email sent."
  124.                     Catch ex As Exception
  125.                         '                        Message = ex.Message
  126.                         ew_Session("iPhoneMessage") = ex.Message
  127.                     End Try
  128.                 End If
  129.  
  130.                 ew_Execute(sSql)
  131.  
  132.                 Dim intResult As Integer, tmpAction As String = "", tmpStatus As String = "", smtpStatus As Boolean, smtpMessage As String
  133.                 Select Case tmptype
  134.                     Case "C"
  135.                         tmpAction = "A"
  136.                         tmpStatus = "BUSY"
  137.                     Case "U"
  138.                         tmpAction = "D"
  139.                     Case "X"
  140.                         tmpAction = "D"
  141.                     Case "T"
  142.                         tmpAction = "A"
  143.                         tmpStatus = "TENTATIVE"
  144.                 End Select
  145.                 Dim tmpStartTime As Date, tmpCallTime As Date
  146.                 Dim tmpEndTime As Date, tmpOutTime As Date
  147.                 If Not IsDBNull(rs1("schStartTime")) Then
  148.                     tmpStartTime = Format(rs1("schStartTime"), "hh:mm:ss tt")
  149.                 Else
  150.                     tmpStartTime = "12:00:00 AM"
  151.                 End If
  152.                 If Not IsDBNull(rs1("schCallTime")) Then
  153.                     tmpCallTime = Format(rs1("schCallTime"), "hh:mm:ss tt")
  154.                 Else
  155.                     tmpCallTime = "12:00:00 AM"
  156.                 End If
  157.                 If Not IsDBNull(rs1("schEndTime")) Then
  158.                     tmpEndTime = Format(rs1("schEndTime"), "hh:mm:ss tt")
  159.                 Else
  160.                     tmpEndTime = "12:00:00 AM"
  161.                 End If
  162.                 If Not IsDBNull(rs1("schOutTime")) Then
  163.                     tmpOutTime = Format(rs1("schEndTime"), "hh:mm:ss tt")
  164.                 Else
  165.                     tmpOutTime = "12:00:00 AM"
  166.                 End If
  167.  
  168.                 If tmpEndTime = "12:00:00 AM" Then
  169.                     tmpEndTime = Format(DateAdd(DateInterval.Hour, 1, tmpStartTime), "hh:mm:ss tt")
  170.                 End If
  171.                 If tmpOutTime = "12:00:00 AM" Then
  172.                     tmpOutTime = Format(DateAdd(DateInterval.Hour, 1, tmpCallTime), "hh:mm:ss tt")
  173.                 End If
  174.                 '            intResult = tlcSendEventInfo(tmpID, ew_FormatDateTime(rs1("schDate"), 2), rs1("evtDescription"), rs1("prtDescription"), ew_FormatDateTime(tmpCallTime, 14), _
  175.                 'ew_FormatDateTime(tmpStartTime, 14), ew_FormatDateTime(tmpEndTime, 14), ew_FormatDateTime(tmpOutTime, 14), rs1("locDescription"), rs1("posDescription"), _
  176.                 'tmpNewStatus, rs1("typDescription"), Session("TFProduction_Status_UserID"), rs1("empEmail"), tmpAction, tmpStatus, tmptype, smtpStatus, smtpMessage)
  177.                 If PSSSendEmailConfirmation = True Or PSSSyncExchangeCalendar = True Then
  178.                     service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, tmpEmail)
  179.                 End If
  180.                 Try
  181.                     If InStr(tmpEmail, "@tfc.org") > 0 And PSSSyncExchangeCalendar = True Then
  182.                         'Create appointment object and set properties as required
  183.                         Dim appt As Appointment = New Appointment(service)
  184.                         appt.Subject = tmpEvtDescription & " - " & tmpPrtDescription
  185.                         'tmpBody = "Event: " & tmpEvtDescription & ", Part: " & tmpPrtDescription & ", Call Time: " & tmpCallTime & _
  186.                         '            ", Start Time: " & tmpStartTime & ", End Time: " & tmpEndTime & ", Out Time: " & tmpOutTime & ", Location: " & tmpLocDescription & _
  187.                         '            ", Position: " & tmpPosDescription & ", Type: " & tmpTypDescription & ", Status: " & tmpStDescription & ", Notes: " & tmpNotes
  188.                         tmpBody = "Position: " & tmpPosDescription & vbCrLf & "Notes: " & tmpNotes
  189.                         appt.Body = tmpBody
  190.                         appt.Start = tmpSchDate & " " & tmpCallTime
  191.                         If tmpOutTime = Nothing Then
  192.                             appt.End = tmpSchDate & " " & tmpStartTime.AddHours(1)
  193.                         Else
  194.                             appt.End = tmpSchDate & " " & tmpOutTime
  195.                         End If
  196.                         appt.IsReminderSet = False
  197.                         'see if it already exists - if so, delete and re-add
  198.                         Dim findResults As FindItemsResults(Of Appointment) = service.FindAppointments(WellKnownFolderName.Calendar, New CalendarView(tmpSchDate, tmpSchDate.AddHours(24)))
  199.                         Dim items As New List(Of Item)()
  200.                         For Each appointment As Appointment In findResults
  201.                             items.Add(appointment)
  202.                         Next
  203.                         If items.Count <> 0 Then
  204.                             service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties)
  205.                             For Each Appointment As Appointment In items
  206.                                 If Not Appointment.IsCancelled Then
  207.                                     If Appointment.Subject = tmpEvtDescription & " - " & tmpPrtDescription Or Appointment.Subject = tmpEvtDescription Then
  208.                                         Appointment.Delete(DeleteMode.HardDelete)
  209.                                         ew_Session("iPhoneMessage") = "Error deleting appointment."
  210.                                     End If
  211.                                 End If
  212.                             Next
  213.                         End If
  214.                         If tmptype = "C" Or tmptype = "T" Then
  215.                             If tmptype = "T" Then
  216.                                 appt.LegacyFreeBusyStatus = LegacyFreeBusyStatus.Tentative
  217.                             End If
  218.                             appt.Save(WellKnownFolderName.Calendar, SendInvitationsMode.SendToNone)
  219.                             ew_Session("iPhoneMessage") = "Error saving appointment."
  220.                         End If
  221.                         'If tmpType = "T" Then
  222.                         '    'service.ImpersonatedUserId = Nothing
  223.                         '    Dim findResults2 As FindItemsResults(Of Appointment) = service.FindAppointments(WellKnownFolderName.Calendar, New CalendarView(tmpSchDate, tmpSchDate.AddHours(24)))
  224.                         '    Dim items2 As New List(Of Item)()
  225.                         '    For Each appointment As Appointment In findResults2
  226.                         '        items2.Add(appointment)
  227.                         '    Next
  228.                         '    If items2.Count <> 0 Then
  229.                         '        service.LoadPropertiesForItems(items2, PropertySet.FirstClassProperties)
  230.                         '        For Each Appointment As Appointment In items2
  231.                         '            If Not Appointment.IsCancelled Then
  232.                         '                If Appointment.Subject = tmpEvtDescription & " - " & tmpPrtDescription or Appointment.Subject = tmpEvtDescription Then
  233.                         '                    'appt.AcceptTentatively(False)
  234.                         '                    Appointment.LegacyFreeBusyStatus = LegacyFreeBusyStatus.Tentative
  235.                         '                    Message = "EWS Appointment marked as Tentative in Outlook calendar."
  236.                         '                End If
  237.                         '            End If
  238.                         '        Next
  239.                         '    End If
  240.                         'End If
  241.                     End If
  242.                 Catch ex As Exception
  243.                     ew_Session("iPhoneMessage") = ex.Message
  244.                 End Try
  245.  
  246.  
  247.                 Response.Redirect("eventdetail3.aspx?ID=" & tmpID)
  248.             End If
  249.             rs1.Close()
  250.             rs1 = Nothing
  251.             Conn.CloseTempDataReader()
  252.             Conn.Dispose()
  253.         End If
  254.     End Sub
  255.  
  256.     Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
  257.         'Return True to force the certificate to be accepted.
  258.         Return True
  259.     End Function
  260.  
  261.     Private Shared Function RedirectionUrlValaditionCallback(ByVal redirectionUrl As String) As Boolean
  262.         Dim result As Boolean = False
  263.         Dim redirectionuri As New Uri(redirectionUrl)
  264.         If redirectionuri.Scheme = "https" Then
  265.             result = True
  266.         End If
  267.         Return result
  268.     End Function
  269.  
  270. End Class
  271.