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