home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / rptDailySchedule.aspx.vb < prev    next >
Text File  |  2010-09-11  |  14KB  |  275 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 rptDailySchedule
  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.Portrait, 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 = 80
  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 sStartDate As String, sEndDate As String, tmpCount As Long, SortOption As Long, sEmployeeID As Long
  45.     Private sEmployeeName As String, tmpLastDate As String, tmpLastEvent As Long = 999999999
  46.     Private tmpEventTotalMinutes As Long, tmpDayTotalMinutes As Long, tmpEmpCount As Long
  47.  
  48.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  49.         sStartDate = Session("tmpStartDate")
  50.         sEndDate = Session("tmpEndDate")
  51.  
  52.         'Create a document and set it's properties
  53.         Dim objDocument As Document = New Document
  54.         objDocument.Creator = "rptDailySchedule.aspx"
  55.         objDocument.Author = "Tony L. Clayton"
  56.         objDocument.Title = "PSS Daily Schedule Report"
  57.         objDocument.InitialPageZoom = PageZoom.FitWidth
  58.  
  59.         'Adds elements to the header groups
  60.         SetPageHeader()
  61.         SetPageFooter()
  62.  
  63.         'Establises connection to the database
  64.         Dim objconnection As OleDbConnection = GetOpenDBConn()
  65.         Dim objData As OleDbDataReader = GetData(objconnection)
  66.  
  67.         'Builds the report
  68.         BuildDocument(objDocument, objData)
  69.  
  70.         'Cleans up database connections
  71.         objData.Close()
  72.         objconnection.Close()
  73.  
  74.         'Outputs the SimpleReport to the current web page
  75.         objDocument.DrawToWeb("rptDailySchedule.pdf")
  76.         Response.End()
  77.     End Sub
  78.  
  79.     Private Sub SetPageHeader()
  80.         'Adds elements to the header group
  81.         With m_objPageHeader
  82.             .Add(New Image(Server.MapPath("images\logo.png"), 0, 0, 0.7F))
  83.             .Add(New Image(Server.MapPath("images\logo.png"), 405, 0, 0.7F))
  84.  
  85.             .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, 504, 10, Font.HelveticaBold, 8, TextAlign.Center))
  86.             .Add(New Label("Daily Schedule Report", 0, 12, 504, 16, Font.HelveticaBold, 16, TextAlign.Center))
  87.             .Add(New Label("As of " & ew_FormatDateTime(Now(), vbLongDate), 0, 30, 504, 9, Font.HelveticaBold, 9, TextAlign.Center))
  88.  
  89.             .Add(New Label("From " & ew_FormatDateTime(sStartDate, vbShortDate) & " through " & ew_FormatDateTime(sEndDate, vbShortDate), 0, 40, 504, 9, Font.HelveticaBold, 9, TextAlign.Left))
  90.  
  91.             .Add(New Label("Event Name", 5, 58, 120, 9, Font.TimesBold, 9))
  92.             .Add(New Label("Part Name", 120, 58, 120, 9, Font.TimesBold, 9))
  93.             .Add(New Label("Actual", 375, 58, 120, 9, Font.TimesBold, 9))
  94.             .Add(New Label("Actual", 425, 58, 120, 9, Font.TimesBold, 9))
  95.  
  96.             .Add(New Label("Employee Name", 20, 68, 100, 9, Font.TimesBold, 9))
  97.             .Add(New Label("Position", 125, 68, 120, 9, Font.TimesBold, 9))
  98.             .Add(New Label("Location", 200, 60, 120, 9, Font.TimesBold, 9))
  99.             .Add(New Label("Start", 378, 68, 120, 9, Font.TimesBold, 9))
  100.             .Add(New Label("End", 430, 68, 120, 9, Font.TimesBold, 9))
  101.             .Add(New Label("Total", 480, 68, 120, 9, Font.TimesBold, 9))
  102.  
  103.             m_objPageHeader.Add(New Line(0, 80, 504, 80))
  104.         End With
  105.     End Sub
  106.  
  107.     Private Sub SetPageFooter()
  108.         'Adds elements to the footer group
  109.         Dim objLabel As PageNumberingLabel = New PageNumberingLabel("Page %%CP%% of %%TP%%", 0, 692, 504, 8, Font.HelveticaBold, 8, TextAlign.Right)
  110.         'objLabel.HasPageNumbering = True
  111.         m_objPageFooter.Add(objLabel)
  112.     End Sub
  113.  
  114.     Private Sub AddNewPage(ByVal document As Document)
  115.         'Adds a new page to the document
  116.         m_objCurrentPage = New ceTe.DynamicPDF.Page(s_objPageDimensions)
  117.         m_objCurrentPage.Elements.Add(m_objPageHeader)
  118.         m_objCurrentPage.Elements.Add(m_objPageFooter)
  119.  
  120.         'Uncomment the line below to add a layout grid to the each page
  121.         'm_objCurrentPage.Elements.Add(New LayoutGrid)
  122.  
  123.         m_fltCurrentY = m_fltBodyTop
  124.         m_blnAlternateBG = False
  125.  
  126.         document.Pages.Add(m_objCurrentPage)
  127.     End Sub
  128.  
  129.     Private Sub BuildDocument(ByVal document As Document, ByVal data As OleDbDataReader)
  130.         'Builds the PDF document with data from the DataReader
  131.         AddNewPage(document)
  132.         While data.Read()
  133.             'Add current record to the document
  134.             AddRecord(document, data)
  135.         End While
  136.         PrintTotals(document)
  137.     End Sub
  138.  
  139.     Private Sub AddRecord(ByVal document As Document, ByVal data As OleDbDataReader)
  140.         Dim intReqHeight As Integer, tmpTime As Long, tmpHours As String, tmpMinutes As String
  141.         intReqHeight = 9
  142.  
  143.         'Adds a new page to the document if needed
  144.         If m_fltCurrentY > m_fltBodyBottom - 20 Then AddNewPage(document)
  145.  
  146.         If tmpLastEvent <> data("evtID") Or data("schDate") <> tmpLastDate Then
  147.             If tmpLastEvent <> 999999999 Then
  148.                 '                m_objPageHeader.Add(New Line(400, m_fltCurrentY, 450, m_fltCurrentY))
  149.                 m_objCurrentPage.Elements.Add(New TextArea(FormatNumber(tmpEmpCount, 0, -2, -2, -2) & " Employee(s)", 150, m_fltCurrentY, 100, intReqHeight, Font.TimesRoman, 10))
  150.                 m_objCurrentPage.Elements.Add(New TextArea("Total: ", 400, m_fltCurrentY, 100, intReqHeight, Font.TimesBold, 10))
  151.                 m_objCurrentPage.Elements.Add(New TextArea(Int(tmpEventTotalMinutes / 60) & ":" & Int(tmpEventTotalMinutes Mod 60).ToString.PadLeft(2, "0"), 480, m_fltCurrentY, 100, intReqHeight, Font.TimesBold, 10))
  152.                 tmpEmpCount = 0
  153.                 tmpEventTotalMinutes = 0
  154.                 m_fltCurrentY += intReqHeight + 2
  155.             End If
  156.         End If
  157.  
  158.         If data("schDate") <> tmpLastDate Then
  159.             If tmpLastDate <> "" Then
  160.                 m_objCurrentPage.Elements.Add(New TextArea("Shift Total: ", 377, m_fltCurrentY, 100, intReqHeight, Font.TimesBold, 10))
  161.                 m_objCurrentPage.Elements.Add(New TextArea(Int(tmpDayTotalMinutes / 60) & ":" & Int(tmpDayTotalMinutes Mod 60).ToString.PadLeft(2, "0"), 480, m_fltCurrentY, 100, intReqHeight, Font.TimesBold, 10))
  162.                 tmpDayTotalMinutes = 0
  163.                 m_fltCurrentY += intReqHeight + 2
  164.             End If
  165.             m_fltCurrentY += 5
  166.             m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 200, (intReqHeight + 6), Grayscale.Black, New WebColor("000000"), 0.0F))
  167.             m_objCurrentPage.Elements.Add(New TextArea(FormatDateTime(data("schDate"), DateFormat.LongDate), 1, m_fltCurrentY, 200, 12, Font.TimesBold, 12, TextAlign.Center, RgbColor.White))
  168.             m_fltCurrentY += intReqHeight + 12
  169.         End If
  170.         tmpLastDate = data("schDate")
  171.  
  172.         If tmpLastEvent <> data("evtID") Then
  173.             If Not IsDBNull(data("evtDescription")) Then
  174.                 m_objCurrentPage.Elements.Add(New TextArea(data("evtDescription"), 5, m_fltCurrentY, 120, intReqHeight, Font.TimesBold, 10))
  175.             End If
  176.             If Not IsDBNull(data("prtDescription")) Then
  177.                 m_objCurrentPage.Elements.Add(New TextArea(data("prtDescription"), 120, m_fltCurrentY, 100, intReqHeight, Font.TimesBold, 10))
  178.             End If
  179.             m_fltCurrentY += intReqHeight + 2
  180.             m_blnAlternateBG = True
  181.         End If
  182.         tmpLastEvent = data("evtID")
  183.  
  184.         'Adds alternating background to document if needed
  185.         If m_blnAlternateBG Then
  186.             m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 504, (intReqHeight + 2), Grayscale.Black, New WebColor("E0E0FF"), 0.0F))
  187.         End If
  188.  
  189.         'Adds Textarea elements to the document with data from current record
  190.         If Not IsDBNull(data("empName")) Then
  191.             m_objCurrentPage.Elements.Add(New TextArea(data("empName"), 20, m_fltCurrentY, 100, intReqHeight, Font.TimesRoman, 10))
  192.         End If
  193.  
  194.         If Not IsDBNull(data("posDescription")) Then
  195.             m_objCurrentPage.Elements.Add(New TextArea(data("posDescription"), 125, m_fltCurrentY, 65, intReqHeight, Font.TimesRoman, 10))
  196.         End If
  197.         If Not IsDBNull(data("locDescription")) Then
  198.             m_objCurrentPage.Elements.Add(New TextArea(data("locDescription"), 200, m_fltCurrentY, 175, intReqHeight, Font.TimesRoman, 10))
  199.         End If
  200.         If Not IsDBNull(data("schActualStart")) Then
  201.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schActualStart"), 14), 375, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  202.         End If
  203.         If Not IsDBNull(data("schActualEnd")) Then
  204.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schActualEnd"), 14), 425, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  205.         End If
  206.         If Not IsDBNull(data("schActualStart")) And Not IsDBNull(data("schActualEnd")) Then
  207.             tmpTime = DateDiff(DateInterval.Minute, data("schActualStart"), data("schActualEnd"))
  208.             tmpHours = Int(tmpTime / 60)
  209.             tmpMinutes = Int(tmpTime Mod 60)
  210.             m_objCurrentPage.Elements.Add(New TextArea(tmpHours & ":" & tmpMinutes.ToString.PadLeft(2, "0"), 480, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  211.             tmpEventTotalMinutes = tmpEventTotalMinutes + tmpMinutes + (tmpHours * 60)
  212.             tmpDayTotalMinutes = tmpDayTotalMinutes + tmpMinutes + (tmpHours * 60)
  213.         End If
  214.  
  215.         tmpEmpCount += 1
  216.         tmpCount += 1
  217.  
  218.         'Toggles alternating background
  219.         m_blnAlternateBG = Not m_blnAlternateBG
  220.         'Increments the current Y position on the page
  221.         m_fltCurrentY += intReqHeight + 2
  222.     End Sub
  223.  
  224.     Private Function GetOpenDBConn() As OleDbConnection
  225.         'Creates and opens a database connection
  226.         Dim sConnStr As String = EW_DB_CONNECTION_STRING
  227.         Dim objConnection As New OleDbConnection(sConnStr)
  228.         objConnection.Open()
  229.         Return objConnection
  230.     End Function
  231.  
  232.     Private Function GetData(ByVal connection As OleDbConnection) As OleDbDataReader
  233.         'Creates a DataReader for the report
  234.         Dim strSQL As String
  235.         Dim objCommand As OleDbCommand = connection.CreateCommand()
  236.         strSQL = "SELECT tblSchedule.schSchID, tblSchedule.schDate, tblEvents.evtDescription, tblParts.prtDescription, " _
  237. & "tblLocations.locDescription, tblEmployees.empName, tblEmployees.empLastName, tblPositions.posDescription, " _
  238. & "tblSchedule.schActualStart, tblSchedule.schActualEnd, tblEvents.evtID " _
  239. & "FROM tblPositions RIGHT JOIN (tblParts RIGHT JOIN (tblLocations RIGHT JOIN (tblEvents " _
  240. & "RIGHT JOIN (tblEmployees INNER JOIN tblSchedule ON tblEmployees.empID = tblSchedule.schEmpID) " _
  241. & "ON tblEvents.evtID = tblSchedule.schEvtID) ON tblLocations.locID = tblSchedule.schLocID) ON tblParts.prtID = " _
  242. & "tblSchedule.schPartsID) ON tblPositions.posID = tblSchedule.schPosID WHERE "
  243.         If Not IsDBNull(sStartDate) Then
  244.             strSQL = strSQL & "(schDate >= #" & sStartDate & "#) "
  245.         End If
  246.         If Not IsDBNull(sEndDate) Then
  247.             If Not IsDBNull(sEndDate) Then
  248.                 strSQL = strSQL & " AND "
  249.             End If
  250.             strSQL = strSQL & "(schDate <= #" & sEndDate & "#) "
  251.         End If
  252.         strSQL = strSQL & "ORDER BY tblSchedule.schDate, tblEvents.evtDescription, tblParts.prtDescription, tblLocations.locDescription, " _
  253. & "tblEmployees.empLastName, tblSchedule.schActualStart"
  254.         Session("strSQL") = strSQL
  255.         objCommand.CommandText = strSQL
  256.         Dim objDataReader As OleDbDataReader = objCommand.ExecuteReader()
  257.  
  258.         Return objDataReader
  259.     End Function
  260.  
  261.     Private Sub PrintTotals(ByVal document As Document)
  262.         m_objCurrentPage.Elements.Add(New TextArea(FormatNumber(tmpEmpCount, 0, -2, -2, -2) & " Employee(s)", 150, m_fltCurrentY, 100, 10, Font.TimesRoman, 10))
  263.         m_objCurrentPage.Elements.Add(New TextArea("Total: ", 400, m_fltCurrentY, 100, 10, Font.TimesBold, 10))
  264.         m_objCurrentPage.Elements.Add(New TextArea(Int(tmpEventTotalMinutes / 60) & ":" & Int(tmpEventTotalMinutes Mod 60).ToString.PadLeft(2, "0"), 480, m_fltCurrentY, 100, 10, Font.TimesBold, 10))
  265.         tmpEventTotalMinutes = 0
  266.         m_fltCurrentY += 10 + 2
  267.         m_blnAlternateBG = Not m_blnAlternateBG
  268.         m_objCurrentPage.Elements.Add(New TextArea("Shift Total: ", 377, m_fltCurrentY, 100, 10, Font.TimesBold, 10))
  269.         m_objCurrentPage.Elements.Add(New TextArea(Int(tmpDayTotalMinutes / 60) & ":" & Int(tmpDayTotalMinutes Mod 60).ToString.PadLeft(2, "0"), 480, m_fltCurrentY, 100, 10, Font.TimesBold, 10))
  270.         tmpDayTotalMinutes = 0
  271.         m_fltCurrentY += 10 + 2
  272.         m_blnAlternateBG = Not m_blnAlternateBG
  273.     End Sub
  274. End Class
  275.