home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / rptScheduleReport.aspx.vb < prev    next >
Text File  |  2012-03-03  |  14KB  |  284 lines

  1. Imports System.Data
  2. Imports System.Data.OleDb
  3. Imports ceTe.DynamicPDF
  4. Imports ceTe.DynamicPDF.PageElements
  5. Imports System.Web.UI
  6.  
  7. Public Class rptScheduleReport
  8.     Inherits AspNetMaker7_tfpssnet
  9.  
  10. #Region " Web Form Designer Generated Code "
  11.  
  12.     'This call is required by the Web Form Designer.
  13.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  14.  
  15.     End Sub
  16.  
  17.  
  18.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  19.         'CODEGEN: This method call is required by the Web Form Designer
  20.         'Do not modify it using the code editor.
  21.         InitializeComponent()
  22.     End Sub
  23.  
  24. #End Region
  25.  
  26.     'Groups for header elements
  27.     Private m_objPageHeader As Group = New Group
  28.     'Groups for footer elements
  29.     Private m_objPageFooter As Group = New Group
  30.  
  31.     'Page Dimensions of pages
  32.     Private Shared s_objPageDimensions As PageDimensions = New PageDimensions(PageSize.Letter, PageOrientation.Landscape, 54.0F)
  33.     'Current page that elements are being added to
  34.     Private m_objCurrentPage As ceTe.DynamicPDF.Page
  35.     'Top Y coordinate for the body of the report
  36.     Private m_fltBodyTop As Single = 74
  37.     'Bottom Y coordinate for the body of the report
  38.     Private m_fltBodyBottom As Single = s_objPageDimensions.Body.Bottom - s_objPageDimensions.Body.Top
  39.     'Current Y coordinate where elements are being added
  40.     Private m_fltCurrentY As Single
  41.     'Used to control the alternating background
  42.     Private m_blnAlternateBG As Boolean
  43.  
  44.     Private sDate As String, eDate As String, tmpCount As Long, SortOption As Long, sEmployeeID As Long
  45.     Private sEmployeeName As String, lastEmpName As String
  46.     Private tmpEventTotalMinutes As Long, tmpDayTotalMinutes As Long
  47.  
  48.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  49.         sDate = Request.QueryString("sDate")
  50.         eDate = Request.QueryString("eDate")
  51.         If ew_Session("tfpssnet_Status_UserLevel") = -1 Then
  52.             sEmployeeID = Request.QueryString("sEmployeeID")
  53.             sEmployeeName = tlcGetEmployeeName(sEmployeeID)
  54.         Else
  55.             sEmployeeID = ew_Session("tfpssnet_Status_UserID")
  56.             sEmployeeName = tlcGetEmployeeName(ew_Session("tfpssnet_Status_UserID"))
  57.         End If
  58.         lastEmpName = "ZZZZZZZ"
  59.  
  60.         'Create a document and set it's properties
  61.         Dim objDocument As Document = New Document
  62.         objDocument.Creator = "rptScheduleReport.aspx"
  63.         objDocument.Author = "Tony L. Clayton"
  64.         objDocument.Title = "PSS Schedule Report"
  65.         objDocument.InitialPageZoom = PageZoom.FitWidth
  66.  
  67.         'Adds elements to the header groups
  68.         SetPageHeader()
  69.         SetPageFooter()
  70.  
  71.         'Establises connection to the database
  72.         Dim objconnection As OleDbConnection = GetOpenDBConn()
  73.         Dim objData As OleDbDataReader = GetData(objconnection)
  74.  
  75.         'Builds the report
  76.         BuildDocument(objDocument, objData)
  77.  
  78.         'Cleans up database connections
  79.         objData.Close()
  80.         objconnection.Close()
  81.  
  82.         'Outputs the SimpleReport to the current web page
  83.         objDocument.DrawToWeb("rptScheduleReport.pdf")
  84.         Response.End()
  85.     End Sub
  86.  
  87.     Private Sub SetPageHeader()
  88.         'Adds elements to the header group
  89.         With m_objPageHeader
  90.             .Add(New Image(Server.MapPath("images\logo.png"), 0, 0, 0.8F))
  91.             .Add(New Image(Server.MapPath("images\logo.png"), 570, 0, 0.8F))
  92.  
  93.             .Add(New Label("P R O D U C T I O N   S E R V I C E S   S C H E D U L I N G   S Y S T E M", 0, 0, 684, 10, Font.HelveticaBold, 8, TextAlign.Center))
  94.             .Add(New Label("Schedule Report", 0, 12, 684, 16, Font.HelveticaBold, 16, TextAlign.Center))
  95.             .Add(New Label(ew_FormatDateTime(Now(), vbLongDate), 0, 30, 684, 12, Font.HelveticaBold, 12, TextAlign.Center))
  96.  
  97.             .Add(New Label("From " & ew_FormatDateTime(sDate, vbShortDate) & " through " & ew_FormatDateTime(eDate, vbShortDate), 0, 40, 684, 9, Font.HelveticaBold, 9, TextAlign.Left))
  98.             If sEmployeeID = 0 Then
  99.                 .Add(New Label("For All Employees", 0, 40, 684, 9, Font.HelveticaBold, 9, TextAlign.Right))
  100.             Else
  101.                 .Add(New Label("For Employee: " & sEmployeeName, 0, 40, 684, 9, Font.HelveticaBold, 9, TextAlign.Right))
  102.             End If
  103.  
  104.             .Add(New Label("Date", 1, 58, 50, 9, Font.TimesBold, 9))
  105.             .Add(New Label("Event Name", 50, 58, 120, 9, Font.TimesBold, 9))
  106.             .Add(New Label("Part Name", 170, 58, 120, 9, Font.TimesBold, 9))
  107.             .Add(New Label("Position", 270, 58, 120, 9, Font.TimesBold, 9))
  108.             .Add(New Label("Status", 335, 58, 120, 9, Font.TimesBold, 9))
  109.             .Add(New Label("Start Time", 385, 58, 120, 9, Font.TimesBold, 9))
  110.             .Add(New Label("End Time", 435, 58, 120, 9, Font.TimesBold, 9))
  111.             .Add(New Label("Call Time", 485, 58, 120, 9, Font.TimesBold, 9))
  112.             .Add(New Label("Out Time", 535, 58, 120, 9, Font.TimesBold, 9))
  113.             .Add(New Label("Actual Start", 580, 58, 120, 9, Font.TimesBold, 9))
  114.             .Add(New Label("Actual End", 635, 58, 120, 9, Font.TimesBold, 9))
  115.  
  116.             m_objPageHeader.Add(New Line(0, 72, 684, 72))
  117.         End With
  118.     End Sub
  119.  
  120.     Private Sub SetPageFooter()
  121.         'Adds elements to the footer group
  122.         Dim objLabel As PageNumberingLabel = New PageNumberingLabel("Page %%CP%% of %%TP%%", 0, 510, 684, 8, Font.HelveticaBold, 8, TextAlign.Right)
  123.         'objLabel.HasPageNumbering = True
  124.         m_objPageFooter.Add(objLabel)
  125.     End Sub
  126.  
  127.     Private Sub AddNewPage(ByVal document As Document)
  128.         'Adds a new page to the document
  129.         m_objCurrentPage = New ceTe.DynamicPDF.Page(s_objPageDimensions)
  130.         m_objCurrentPage.Elements.Add(m_objPageHeader)
  131.         m_objCurrentPage.Elements.Add(m_objPageFooter)
  132.  
  133.         'Uncomment the line below to add a layout grid to the each page
  134.         'm_objCurrentPage.Elements.Add(New LayoutGrid)
  135.  
  136.         m_fltCurrentY = m_fltBodyTop
  137.         m_blnAlternateBG = False
  138.  
  139.         document.Pages.Add(m_objCurrentPage)
  140.     End Sub
  141.  
  142.     Private Sub BuildDocument(ByVal document As Document, ByVal data As OleDbDataReader)
  143.         'Builds the PDF document with data from the DataReader
  144.         AddNewPage(document)
  145.         While data.Read()
  146.             'Add current record to the document
  147.             AddRecord(document, data)
  148.         End While
  149.         Call PrintTotals(document)
  150.     End Sub
  151.  
  152.     Private Sub AddRecord(ByVal document As Document, ByVal data As OleDbDataReader)
  153.         Dim intReqHeight As Integer, tmpTime As Long, tmpHours As String, tmpMinutes As String
  154.         intReqHeight = 9
  155.  
  156.         'Adds a new page to the document if needed
  157.         If m_fltCurrentY > m_fltBodyBottom - 20 Then AddNewPage(document)
  158.  
  159.         'Adds alternating background to document if needed
  160.         If m_blnAlternateBG Then
  161.             If Not IsDBNull(data("schNotes")) Then
  162.                 m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 684, (intReqHeight + 4) * 2, Grayscale.Black, New WebColor("E0E0FF"), 0.0F))
  163.             Else
  164.                 m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 684, (intReqHeight + 4), Grayscale.Black, New WebColor("E0E0FF"), 0.0F))
  165.             End If
  166.         End If
  167.  
  168.         If data("empName") <> lastEmpName Then
  169.             If lastEmpName <> "ZZZZZZZ" Then
  170.                 m_objCurrentPage.Elements.Add(New TextArea("Total Scheduled Time: " & Int(tmpEventTotalMinutes / 60) & ":" & Int(tmpEventTotalMinutes Mod 60).ToString.PadLeft(2, "0"), 480, m_fltCurrentY, 200, intReqHeight, Font.TimesBold, 10))
  171.                 tmpEventTotalMinutes = 0
  172.                 m_fltCurrentY += intReqHeight + 5
  173.             End If
  174.             m_objCurrentPage.Elements.Add(New TextArea(data("empName"), 1, m_fltCurrentY, 200, intReqHeight, Font.TimesBold, 12))
  175.             m_fltCurrentY += intReqHeight + 5
  176.         End If
  177.         lastEmpName = data("empName")
  178.  
  179.         'Adds Textarea elements to the document with data from current record
  180.         If Not IsDBNull(data("schDate")) Then
  181.             m_objCurrentPage.Elements.Add(New TextArea(data("schDate"), 1, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  182.         End If
  183.         If Not IsDBNull(data("evtDescription")) Then
  184.             m_objCurrentPage.Elements.Add(New TextArea(data("evtDescription"), 50, m_fltCurrentY, 120, intReqHeight, Font.TimesRoman, 10))
  185.         End If
  186.         If Not IsDBNull(data("prtDescription")) Then
  187.             m_objCurrentPage.Elements.Add(New TextArea(data("prtDescription"), 170, m_fltCurrentY, 100, intReqHeight, Font.TimesRoman, 10))
  188.         End If
  189.         If Not IsDBNull(data("posDescription")) Then
  190.             m_objCurrentPage.Elements.Add(New TextArea(data("posDescription"), 270, m_fltCurrentY, 65, intReqHeight, Font.TimesRoman, 10))
  191.         End If
  192.         If Not IsDBNull(data("stDescription")) Then
  193.             m_objCurrentPage.Elements.Add(New TextArea(data("stDescription"), 335, m_fltCurrentY, 60, intReqHeight, Font.TimesRoman, 10))
  194.         End If
  195.         If Not IsDBNull(data("schStartTime")) Then
  196.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schStartTime"), 14), 395, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  197.         End If
  198.         If Not IsDBNull(data("schEndTime")) Then
  199.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schEndTime"), 14), 445, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  200.         End If
  201.         If Not IsDBNull(data("schCallTime")) Then
  202.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schCallTime"), 14), 495, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  203.         End If
  204.         If Not IsDBNull(data("schOutTime")) Then
  205.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schOutTime"), 14), 545, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  206.         End If
  207.         If Not IsDBNull(data("schActualStart")) Then
  208.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schActualStart"), 14), 595, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  209.         End If
  210.         If Not IsDBNull(data("schActualEnd")) Then
  211.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schActualEnd"), 14), 645, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  212.         End If
  213.         m_fltCurrentY += intReqHeight + 5
  214.         If Not IsDBNull(data("schNotes")) Then
  215.             m_objCurrentPage.Elements.Add(New TextArea(data("schNotes"), 25, m_fltCurrentY, 500, intReqHeight, Font.TimesRoman, 10))
  216.         End If
  217.         If Not IsDBNull(data("schCallTime")) And Not IsDBNull(data("schOutTime")) Then
  218.             tmpTime = DateDiff(DateInterval.Minute, data("schCallTime"), data("schOuttime"))
  219.             tmpHours = Int(tmpTime / 60)
  220.             tmpMinutes = Int(tmpTime Mod 60)
  221.             m_objCurrentPage.Elements.Add(New TextArea("Scheduled Time: " & tmpHours & ":" & tmpMinutes.ToString.PadLeft(2, "0"), 510, m_fltCurrentY, 150, intReqHeight, Font.TimesRoman, 10))
  222.             tmpEventTotalMinutes = tmpEventTotalMinutes + tmpMinutes + (tmpHours * 60)
  223.         End If
  224.  
  225.         tmpCount += 1
  226.  
  227.         'Toggles alternating background
  228.         m_blnAlternateBG = Not m_blnAlternateBG
  229.         'Increments the current Y position on the page
  230.         m_fltCurrentY += intReqHeight + 5
  231.     End Sub
  232.  
  233.     Private Function GetOpenDBConn() As OleDbConnection
  234.         'Creates and opens a database connection
  235.         Dim sConnStr As String = EW_DB_CONNECTION_STRING
  236.         Dim objConnection As New OleDbConnection(sConnStr)
  237.         objConnection.Open()
  238.         Return objConnection
  239.     End Function
  240.  
  241.     Private Function GetData(ByVal connection As OleDbConnection) As OleDbDataReader
  242.         'Creates a DataReader for the report
  243.         Dim strSQL As String
  244.         Dim objCommand As OleDbCommand = connection.CreateCommand()
  245.         strSQL = "SELECT tblSchedule.schDate, tblSchedule.schEmpID, tblEmployees.empName, tblEvents.evtDescription, " _
  246. & "tblParts.prtDescription, tblPositions.posDescription, tblScheduleStatus.stDescription, tblSchedule.schStartTime, " _
  247. & "tblSchedule.schEndTime, tblSchedule.schCallTime, tblSchedule.schOutTime, tblSchedule.schActualStart, " _
  248. & "tblSchedule.schActualEnd, tblSchedule.schStatus, tblSchedule.schNotes " _
  249. & "FROM tblScheduleStatus RIGHT JOIN (tblPositions RIGHT JOIN (tblParts RIGHT JOIN (tblEvents RIGHT JOIN " _
  250. & "(tblEmployees INNER JOIN tblSchedule ON tblEmployees.empID = tblSchedule.schEmpID) ON tblEvents.evtID = " _
  251. & "tblSchedule.schEvtID) ON tblParts.prtID = tblSchedule.schPartsID) ON tblPositions.posID = tblSchedule.schPosID) " _
  252. & "ON tblScheduleStatus.stID = tblSchedule.schStatus "
  253.         If sEmployeeID = 0 Then
  254.             strSQL = strSQL & "WHERE "
  255.         Else
  256.             strSQL = strSQL & "WHERE (tblSchedule.schEmpID = " & sEmployeeID & ") AND "
  257.         End If
  258.         If Not IsDBNull(sDate) Or Not IsDBNull(eDate) Then
  259.             If Not IsDBNull(sDate) Then
  260.                 strSQL = strSQL & "(schDate >= #" & sDate & "#) "
  261.             End If
  262.             If Not IsDBNull(eDate) Then
  263.                 If Not IsDBNull(sDate) Then
  264.                     strSQL = strSQL & " AND "
  265.                 End If
  266.                 strSQL = strSQL & "(schDate <= #" & eDate & "#) "
  267.             End If
  268.         End If
  269.         strSQL = strSQL & "ORDER BY empName, schDate, schStartTime"
  270.         objCommand.CommandText = strSQL
  271.         Dim objDataReader As OleDbDataReader = objCommand.ExecuteReader()
  272.  
  273.         Return objDataReader
  274.     End Function
  275.  
  276.     Private Sub PrintTotals(ByVal document As Document)
  277.         If lastEmpName <> "ZZZZZZZ" Then
  278.             m_objCurrentPage.Elements.Add(New TextArea("Total Scheduled Time: " & Int(tmpEventTotalMinutes / 60) & ":" & Int(tmpEventTotalMinutes Mod 60).ToString.PadLeft(2, "0"), 480, m_fltCurrentY, 200, 10, Font.TimesBold, 10))
  279.             tmpEventTotalMinutes = 0
  280.         End If
  281.     End Sub
  282.  
  283. End Class
  284.