home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / rptDailyScheduleByEmployee.aspx.vb < prev    next >
Text File  |  2010-09-11  |  14KB  |  270 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 rptDailyScheduleByEmployee
  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.  
  52.         'Create a document and set it's properties
  53.         Dim objDocument As Document = New Document
  54.         objDocument.Creator = "rptDailScheduleByEmployee.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("rptDailScheduleByEmployee.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", 20, 60, 120, 9, Font.TimesBold, 9))
  92.             .Add(New Label("Part", 125, 60, 120, 9, Font.TimesBold, 9))
  93.             .Add(New Label("Position", 225, 60, 120, 9, Font.TimesBold, 9))
  94.             .Add(New Label("Location", 280, 60, 120, 9, Font.TimesBold, 9))
  95.             .Add(New Label("Actual Start", 385, 60, 120, 9, Font.TimesBold, 9))
  96.             .Add(New Label("Actual End", 435, 60, 120, 9, Font.TimesBold, 9))
  97.             .Add(New Label("Total", 483, 60, 120, 9, Font.TimesBold, 9))
  98.  
  99.             m_objPageHeader.Add(New Line(0, 72, 504, 72))
  100.         End With
  101.     End Sub
  102.  
  103.     Private Sub SetPageFooter()
  104.         'Adds elements to the footer group
  105.         Dim objLabel As PageNumberingLabel = New PageNumberingLabel("Page %%CP%% of %%TP%%", 0, 692, 504, 8, Font.HelveticaBold, 8, TextAlign.Right)
  106.         'objLabel.HasPageNumbering = True
  107.         m_objPageFooter.Add(objLabel)
  108.     End Sub
  109.  
  110.     Private Sub AddNewPage(ByVal document As Document)
  111.         'Adds a new page to the document
  112.         m_objCurrentPage = New ceTe.DynamicPDF.Page(s_objPageDimensions)
  113.         m_objCurrentPage.Elements.Add(m_objPageHeader)
  114.         m_objCurrentPage.Elements.Add(m_objPageFooter)
  115.  
  116.         'Uncomment the line below to add a layout grid to the each page
  117.         'm_objCurrentPage.Elements.Add(New LayoutGrid)
  118.  
  119.         m_fltCurrentY = m_fltBodyTop
  120.         m_blnAlternateBG = False
  121.  
  122.         document.Pages.Add(m_objCurrentPage)
  123.     End Sub
  124.  
  125.     Private Sub BuildDocument(ByVal document As Document, ByVal data As OleDbDataReader)
  126.         'Builds the PDF document with data from the DataReader
  127.         AddNewPage(document)
  128.         While data.Read()
  129.             'Add current record to the document
  130.             AddRecord(document, data)
  131.         End While
  132.         '        PrintTotals(document)
  133.     End Sub
  134.  
  135.     Private Sub AddRecord(ByVal document As Document, ByVal data As OleDbDataReader)
  136.         Dim intReqHeight As Integer, tmpTime As Long, tmpHours As String, tmpMinutes As String
  137.         intReqHeight = 9
  138.  
  139.         'Adds a new page to the document if needed
  140.         If m_fltCurrentY > m_fltBodyBottom - 20 Then AddNewPage(document)
  141.  
  142.         'If tmpLastEvent <> data("evtID") Or data("schDate") <> tmpLastDate Then
  143.         '    If tmpLastEvent <> 999999999 Then
  144.         '        '                m_objPageHeader.Add(New Line(400, m_fltCurrentY, 450, m_fltCurrentY))
  145.         '        m_objCurrentPage.Elements.Add(New TextArea("Total: ", 350, m_fltCurrentY, 100, intReqHeight, Font.TimesBold, 10))
  146.         '        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))
  147.         '        tmpEventTotalMinutes = 0
  148.         '        m_fltCurrentY += intReqHeight + 2
  149.         '    End If
  150.         'End If
  151.  
  152.         'If tmpLastEvent <> data("evtID") Then
  153.         '    If Not IsDBNull(data("evtDescription")) Then
  154.         '        m_objCurrentPage.Elements.Add(New TextArea(data("evtDescription"), 5, m_fltCurrentY, 120, intReqHeight, Font.TimesBold, 10))
  155.         '    End If
  156.         '    If Not IsDBNull(data("prtDescription")) Then
  157.         '        m_objCurrentPage.Elements.Add(New TextArea(data("prtDescription"), 120, m_fltCurrentY, 100, intReqHeight, Font.TimesBold, 10))
  158.         '    End If
  159.         '    m_fltCurrentY += intReqHeight + 2
  160.         '    m_blnAlternateBG = True
  161.         'End If
  162.         'tmpLastEvent = data("evtID")
  163.  
  164.         If data("empName") <> tmpLastEmpName Then
  165.             m_fltCurrentY += 5
  166.             m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 120, (intReqHeight + 2), Grayscale.Black, New WebColor("000000"), 0.0F))
  167.             m_objCurrentPage.Elements.Add(New TextArea(data("empName"), 1, m_fltCurrentY, 200, 10, Font.TimesBold, 10, TextAlign.Left, RgbColor.White))
  168.             '            m_objCurrentPage.Elements.Add(New Line(0, m_fltCurrentY + 11, 130, m_fltCurrentY + 11))
  169.             m_fltCurrentY += intReqHeight + 2
  170.             tmpLastDate = CDate("1/1/1950")
  171.         End If
  172.         tmpLastEmpName = data("empName")
  173.  
  174.         If data("schDate") <> tmpLastDate And tmpLastDate <> "" Then
  175.             m_objCurrentPage.Elements.Add(New TextArea(FormatDateTime(data("schDate"), DateFormat.LongDate), 1, m_fltCurrentY, 200, 10, Font.TimesBold, 10))
  176.             m_fltCurrentY += intReqHeight
  177.         End If
  178.         tmpLastDate = data("schDate")
  179.  
  180.         'Adds alternating background to document if needed
  181.         'If m_blnAlternateBG Then
  182.         '    m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 504, (intReqHeight + 2), Grayscale.Black, New WebColor("E0E0FF"), 0.0F))
  183.         'End If
  184.  
  185.         'Adds Textarea elements to the document with data from current record
  186.         If Not IsDBNull(data("evtDescription")) Then
  187.             m_objCurrentPage.Elements.Add(New TextArea(data("evtDescription"), 20, m_fltCurrentY, 100, intReqHeight, Font.TimesRoman, 10))
  188.         End If
  189.         If Not IsDBNull(data("prtDescription")) Then
  190.             m_objCurrentPage.Elements.Add(New TextArea(data("prtDescription"), 125, m_fltCurrentY, 98, intReqHeight, Font.TimesRoman, 10))
  191.         End If
  192.         If Not IsDBNull(data("posDescription")) Then
  193.             m_objCurrentPage.Elements.Add(New TextArea(data("posDescription"), 225, m_fltCurrentY, 55, intReqHeight, Font.TimesRoman, 10))
  194.         End If
  195.         If Not IsDBNull(data("locDescription")) Then
  196.             m_objCurrentPage.Elements.Add(New TextArea(data("locDescription"), 280, m_fltCurrentY, 105, intReqHeight, Font.TimesRoman, 10))
  197.         End If
  198.         If Not IsDBNull(data("schActualStart")) Then
  199.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schActualStart"), 14), 385, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  200.         End If
  201.         If Not IsDBNull(data("schActualEnd")) Then
  202.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("schActualEnd"), 14), 435, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  203.         End If
  204.         If Not IsDBNull(data("schActualStart")) And Not IsDBNull(data("schActualEnd")) Then
  205.             tmpTime = DateDiff(DateInterval.Minute, data("schActualStart"), data("schActualEnd"))
  206.             tmpHours = Int(tmpTime / 60)
  207.             tmpMinutes = Int(tmpTime Mod 60)
  208.             m_objCurrentPage.Elements.Add(New TextArea(tmpHours & ":" & tmpMinutes.ToString.PadLeft(2, "0"), 483, m_fltCurrentY, 50, intReqHeight, Font.TimesRoman, 10))
  209.             tmpEventTotalMinutes = tmpEventTotalMinutes + tmpMinutes + (tmpHours * 60)
  210.             tmpDayTotalMinutes = tmpDayTotalMinutes + tmpMinutes + (tmpHours * 60)
  211.         End If
  212.  
  213.         tmpCount += 1
  214.  
  215.         'Toggles alternating background
  216.         m_blnAlternateBG = Not m_blnAlternateBG
  217.         'Increments the current Y position on the page
  218.         m_fltCurrentY += intReqHeight + 2
  219.     End Sub
  220.  
  221.     Private Function GetOpenDBConn() As OleDbConnection
  222.         'Creates and opens a database connection
  223.         Dim sConnStr As String = EW_DB_CONNECTION_STRING
  224.         Dim objConnection As New OleDbConnection(sConnStr)
  225.         objConnection.Open()
  226.         Return objConnection
  227.     End Function
  228.  
  229.     Private Function GetData(ByVal connection As OleDbConnection) As OleDbDataReader
  230.         'Creates a DataReader for the report
  231.         Dim strSQL As String
  232.         Dim objCommand As OleDbCommand = connection.CreateCommand()
  233.         strSQL = "SELECT tblSchedule.schSchID, tblSchedule.schDate, tblEvents.evtDescription, tblParts.prtDescription, " _
  234. & "tblLocations.locDescription, tblEmployees.empName, tblEmployees.empLastName, tblPositions.posDescription, " _
  235. & "tblSchedule.schActualStart, tblSchedule.schActualEnd, tblEvents.evtID " _
  236. & "FROM tblPositions RIGHT JOIN (tblParts RIGHT JOIN (tblLocations RIGHT JOIN (tblEvents " _
  237. & "RIGHT JOIN (tblEmployees INNER JOIN tblSchedule ON tblEmployees.empID = tblSchedule.schEmpID) " _
  238. & "ON tblEvents.evtID = tblSchedule.schEvtID) ON tblLocations.locID = tblSchedule.schLocID) ON tblParts.prtID = " _
  239. & "tblSchedule.schPartsID) ON tblPositions.posID = tblSchedule.schPosID WHERE "
  240.         If Not IsDBNull(sStartDate) Then
  241.             strSQL = strSQL & "(schDate >= #" & sStartDate & "#) "
  242.         End If
  243.         If Not IsDBNull(sEndDate) Then
  244.             If Not IsDBNull(sEndDate) Then
  245.                 strSQL = strSQL & " AND "
  246.             End If
  247.             strSQL = strSQL & "(schDate <= #" & sEndDate & "#) "
  248.         End If
  249.         strSQL = strSQL & "ORDER BY tblEmployees.empLastName, tblSchedule.schDate, tblEvents.evtDescription, " _
  250. & "tblParts.prtDescription, tblLocations.locDescription, tblSchedule.schActualStart"
  251.         Session("strSQL") = strSQL
  252.         objCommand.CommandText = strSQL
  253.         Dim objDataReader As OleDbDataReader = objCommand.ExecuteReader()
  254.  
  255.         Return objDataReader
  256.     End Function
  257.  
  258.     Private Sub PrintTotals(ByVal document As Document)
  259.         m_objCurrentPage.Elements.Add(New TextArea("Total: ", 350, m_fltCurrentY, 100, 10, Font.TimesBold, 10))
  260.         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))
  261.         tmpEventTotalMinutes = 0
  262.         m_fltCurrentY += 10 + 2
  263.         m_blnAlternateBG = Not m_blnAlternateBG
  264.         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))
  265.         tmpDayTotalMinutes = 0
  266.         m_fltCurrentY += 10 + 2
  267.         m_blnAlternateBG = Not m_blnAlternateBG
  268.     End Sub
  269. End Class
  270.