home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / rptLPRReport.aspx.vb < prev    next >
Text File  |  2012-02-19  |  17KB  |  345 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 rptLPRReport
  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 = 100
  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 tmpStartDate As String, tmpEndDate As String, tmpCount As Long, SortOption As Long, tmpEmployeeID As Long, tmpEmployeeName As String
  45.     Private tmpLocationID As Long, tmpLocationDesc As String, tmpStatusID As Long, tmpStatusDesc As String
  46.     Private intReqHeight As Integer, intLine1ReqHeight As Integer
  47.  
  48.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  49.         tmpStartDate = ew_Session("tmpStartDate")
  50.         tmpEndDate = ew_Session("tmpEndDate")
  51.         If ew_Session("tfpssnet_Status_UserLevel") = -1 Or ew_Session("tfpssnet_Status_UserLevel") = 3 Or ew_Session("tfpssnet_Status_Userlevel") = 4 Then
  52.             tmpEmployeeID = ew_Session("tmpEmployeeID")
  53.             '            tmpEmployeeName = tlcGetEmployeeName(tmpEmployeeID)
  54.             tmpEmployeeName = ew_Session("tmpEmployeeText")
  55.         Else
  56.             tmpEmployeeID = ew_Session("tfpssnet_Status_UserID")
  57.             tmpEmployeeName = tlcGetEmployeeName(ew_Session("tfpssnet_Status_UserID"))
  58.         End If
  59.         tmpLocationID = ew_Session("tmpLocationID")
  60.         tmpLocationDesc = ew_Session("tmpLocationDesc")
  61.         tmpStatusID = ew_Session("tmpStatusID")
  62.         tmpStatusDesc = ew_Session("tmpStatusDesc")
  63.  
  64.         'Create a document and set it's properties
  65.         Dim objDocument As Document = New Document
  66.         objDocument.Creator = "rptLPRReport.aspx"
  67.         objDocument.Author = "Tony L. Clayton"
  68.         objDocument.Title = "Lighting Problem Report"
  69.         objDocument.InitialPageZoom = PageZoom.FitWidth
  70.  
  71.         'Adds elements to the header groups
  72.         SetPageHeader()
  73.         SetPageFooter()
  74.  
  75.         'Establises connection to the database
  76.         Dim objconnection As OleDbConnection = GetOpenDBConn()
  77.         Dim objData As OleDbDataReader = GetData(objconnection)
  78.  
  79.         'Builds the report
  80.         BuildDocument(objDocument, objData)
  81.  
  82.         'Cleans up database connections
  83.         objData.Close()
  84.         objconnection.Close()
  85.  
  86.         'Outputs the SimpleReport to the current web page
  87.         objDocument.DrawToWeb("rptLPRReport.pdf")
  88.         Response.End()
  89.     End Sub
  90.  
  91.     Private Sub SetPageHeader()
  92.         'Adds elements to the header group
  93.         With m_objPageHeader
  94.             .Add(New Image(Server.MapPath("images\logo.png"), 0, 0, 0.8F))
  95.             .Add(New Image(Server.MapPath("images\logo.png"), 570, 0, 0.8F))
  96.  
  97.             .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))
  98.             .Add(New Label("Problem Report", 0, 12, 684, 16, Font.HelveticaBold, 16, TextAlign.Center))
  99.             .Add(New Label(ew_FormatDateTime(Now(), vbLongDate), 0, 30, 684, 12, Font.HelveticaBold, 12, TextAlign.Center))
  100.  
  101.             If tmpStartDate = "" Then
  102.                 .Add(New Label("Ending Date: " & FormatDateTime(tmpEndDate), 0, 40, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  103.             Else
  104.                 .Add(New Label("From " & FormatDateTime(tmpStartDate) & " through " & FormatDateTime(tmpEndDate), 0, 40, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  105.             End If
  106.             If tmpEmployeeID = "0" Then
  107.                 .Add(New Label("All Employees", 0, 50, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  108.             Else
  109.                 .Add(New Label("Employee: " & tmpEmployeeName, 0, 50, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  110.             End If
  111.             If tmpLocationID = "0" Then
  112.                 .Add(New Label("All Locations", 0, 60, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  113.             Else
  114.                 .Add(New Label("Location: " & tmpLocationDesc, 0, 60, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  115.             End If
  116.             If tmpStatusID = "0" Then
  117.                 .Add(New Label("All Status Codes", 0, 70, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  118.             Else
  119.                 .Add(New Label("Status: " & tmpStatusDesc, 0, 70, 684, 9, Font.Helvetica, 9, TextAlign.Left))
  120.             End If
  121.  
  122.             .Add(New Label("Fixture", 230, 76, 100, 9, Font.TimesBold, 9))
  123.             .Add(New Label("Fixture", 305, 76, 100, 9, Font.TimesBold, 9))
  124.             .Add(New Label("Fixture", 355, 76, 100, 9, Font.TimesBold, 9))
  125.  
  126.             .Add(New Label("Date", 1, 84, 50, 9, Font.TimesBold, 9))
  127.             .Add(New Label("Employee", 50, 84, 100, 9, Font.TimesBold, 9))
  128.             .Add(New Label("Location", 125, 84, 100, 9, Font.TimesBold, 9))
  129.             .Add(New Label("Location", 230, 84, 100, 9, Font.TimesBold, 9))
  130.             .Add(New Label("Type", 310, 84, 50, 9, Font.TimesBold, 9))
  131.             .Add(New Label("Num", 360, 84, 50, 9, Font.TimesBold, 9))
  132.             .Add(New Label("Channel", 390, 84, 50, 9, Font.TimesBold, 9))
  133.             .Add(New Label("Priority", 430, 84, 50, 9, Font.TimesBold, 9))
  134.             .Add(New Label("Short Desc", 475, 84, 75, 9, Font.TimesBold, 9))
  135.             .Add(New Label("Status", 565, 84, 75, 9, Font.TimesBold, 9))
  136.             .Add(New Label("Status Chngd By", 620, 84, 75, 9, Font.TimesBold, 9))
  137.  
  138.             m_objPageHeader.Add(New Line(0, 96, 684, 96))
  139.         End With
  140.     End Sub
  141.  
  142.     Private Sub SetPageFooter()
  143.         'Adds elements to the footer group
  144.         Dim objLabel As PageNumberingLabel = New PageNumberingLabel("Page %%CP%% of %%TP%%", 0, 510, 684, 8, Font.HelveticaBold, 8, TextAlign.Right)
  145.         'objLabel.HasPageNumbering = True
  146.         m_objPageFooter.Add(objLabel)
  147.     End Sub
  148.  
  149.     Private Sub AddNewPage(ByVal document As Document)
  150.         'Adds a new page to the document
  151.         m_objCurrentPage = New ceTe.DynamicPDF.Page(s_objPageDimensions)
  152.         m_objCurrentPage.Elements.Add(m_objPageHeader)
  153.         m_objCurrentPage.Elements.Add(m_objPageFooter)
  154.  
  155.         'Uncomment the line below to add a layout grid to the each page
  156.         'm_objCurrentPage.Elements.Add(New LayoutGrid)
  157.  
  158.         m_fltCurrentY = m_fltBodyTop
  159.         m_blnAlternateBG = False
  160.  
  161.         document.Pages.Add(m_objCurrentPage)
  162.     End Sub
  163.  
  164.     Private Sub BuildDocument(ByVal document As Document, ByVal data As OleDbDataReader)
  165.         'Builds the PDF document with data from the DataReader
  166.         AddNewPage(document)
  167.         While data.Read()
  168.             'Add current record to the document
  169.             AddRecord(document, data)
  170.         End While
  171.         PrintTotals(document)
  172.     End Sub
  173.  
  174.     Private Sub AddRecord(ByVal document As Document, ByVal data As OleDbDataReader)
  175.         Dim tmpTemp As String
  176.         intReqHeight = GetReqRecordHeight(data)
  177.         intLine1ReqHeight = GetLine1RecordHeight(data)
  178.  
  179.         'Adds a new page to the document if needed
  180.         If m_fltCurrentY > m_fltBodyBottom - 20 Then AddNewPage(document)
  181.  
  182.         'Adds alternating background to document if needed
  183.         If m_blnAlternateBG Then
  184.             If Not IsDBNull(data("lprDesc")) Then
  185.                 m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 684, (intReqHeight + 16), Grayscale.Black, New WebColor("E0E0FF"), 0.0F))
  186.             Else
  187.                 m_objCurrentPage.Elements.Add(New Rectangle(0, m_fltCurrentY, 684, (intLine1ReqHeight + 4), Grayscale.Black, New WebColor("E0E0FF"), 0.0F))
  188.             End If
  189.         End If
  190.  
  191.         'Adds Textarea elements to the document with data from current record
  192.         If Not IsDBNull(data("lprDate")) Then
  193.             m_objCurrentPage.Elements.Add(New TextArea(data("lprDate"), 1, m_fltCurrentY, 50, intLine1ReqHeight, Font.TimesRoman, 10))
  194.         End If
  195.         If Not IsDBNull(data("empName")) Then
  196.             m_objCurrentPage.Elements.Add(New TextArea(data("empName"), 50, m_fltCurrentY, 120, intLine1ReqHeight, Font.TimesRoman, 10))
  197.         End If
  198.         If Not IsDBNull(data("locDescription")) Then
  199.             m_objCurrentPage.Elements.Add(New TextArea(data("locDescription"), 125, m_fltCurrentY, 100, intLine1ReqHeight, Font.TimesRoman, 10))
  200.         End If
  201.         If Not IsDBNull(data("floDescription")) Then
  202.             m_objCurrentPage.Elements.Add(New TextArea(data("floDescription"), 230, m_fltCurrentY, 65, intLine1ReqHeight, Font.TimesRoman, 10))
  203.         End If
  204.         If Not IsDBNull(data("ftyDescription")) Then
  205.             m_objCurrentPage.Elements.Add(New TextArea(data("ftyDescription"), 310, m_fltCurrentY, 60, intLine1ReqHeight, Font.TimesRoman, 10))
  206.         End If
  207.         If Not IsDBNull(data("lprFixtureNumber")) Then
  208.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("lprFixtureNumber"), 14), 365, m_fltCurrentY, 50, intLine1ReqHeight, Font.TimesRoman, 10))
  209.         End If
  210.         If Not IsDBNull(data("lprChannelNumber")) Then
  211.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("lprChannelNumber"), 14), 400, m_fltCurrentY, 50, intLine1ReqHeight, Font.TimesRoman, 10))
  212.         End If
  213.         If Not IsDBNull(data("lprPriority")) Then
  214.             Select Case data("lprPriority")
  215.                 Case "1"
  216.                     tmpTemp = "Low"
  217.                 Case "2"
  218.                     tmpTemp = "Medium"
  219.                 Case "3"
  220.                     tmpTemp = "High"
  221.                 Case Else
  222.                     tmpTemp = ""
  223.             End Select
  224.             m_objCurrentPage.Elements.Add(New TextArea(tmpTemp, 430, m_fltCurrentY, 50, intLine1ReqHeight, Font.TimesRoman, 10))
  225.         End If
  226.         If Not IsDBNull(data("lprShortDesc")) Then
  227.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("lprShortDesc"), 14), 475, m_fltCurrentY, 50, intLine1ReqHeight, Font.TimesRoman, 10))
  228.         End If
  229.         If Not IsDBNull(data("lstDescription")) Then
  230.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("lstDescription"), 14), 565, m_fltCurrentY, 50, intLine1ReqHeight, Font.TimesRoman, 10))
  231.         End If
  232.         If Not IsDBNull(data("lprSTChangedBy")) Then
  233.             m_objCurrentPage.Elements.Add(New TextArea(ew_FormatDateTime(data("lprSTChangedBy"), 14), 620, m_fltCurrentY, 50, intLine1ReqHeight, Font.TimesRoman, 10))
  234.         End If
  235.         If Not IsDBNull(data("lprDesc")) Then
  236.             m_fltCurrentY += intLine1ReqHeight + 2
  237.             m_objCurrentPage.Elements.Add(New TextArea(data("lprDesc"), 15, m_fltCurrentY, 650, intReqHeight, Font.TimesRoman, 10))
  238.             m_fltCurrentY += intReqHeight + 2
  239.         End If
  240.  
  241.         tmpCount += 1
  242.  
  243.         'Toggles alternating background
  244.         m_blnAlternateBG = Not m_blnAlternateBG
  245.         'Increments the current Y position on the page
  246.         m_fltCurrentY += intLine1ReqHeight + 2
  247.     End Sub
  248.  
  249.     Function GetReqRecordHeight(ByVal data As OleDbDataReader) As Long
  250.         Dim intRecordHeight As Integer, intNameHeight As Integer, intDescHeight As Integer
  251.         Dim fontTNR As Font, tmpName As String
  252.         fontTNR = Font.TimesRoman
  253.         tmpName = SafeDBNull(data("empName"))
  254.         intNameHeight = fontTNR.GetTextLines(tmpName.ToCharArray(), 120, 9).GetTextHeight()
  255.         intRecordHeight = intNameHeight
  256.         If Not IsDBNull(data("lprDesc")) Then
  257.             intDescHeight = fontTNR.GetTextLines((data("lprDesc")).ToCharArray(), 635, 9).GetTextHeight()
  258.             If intDescHeight > intRecordHeight Then intRecordHeight = intDescHeight
  259.         End If
  260.         GetReqRecordHeight = intRecordHeight
  261.     End Function
  262.  
  263.     Function GetLine1RecordHeight(ByVal data As OleDbDataReader) As Long
  264.         Dim intRecordHeight As Integer, intNameHeight As Integer
  265.         Dim fontTNR As Font, tmpName As String
  266.         fontTNR = Font.TimesRoman
  267.         tmpName = SafeDBNull(data("empName"))
  268.         intNameHeight = fontTNR.GetTextLines(tmpName.ToCharArray(), 120, 9).GetTextHeight()
  269.         intRecordHeight = intNameHeight
  270.         GetLine1RecordHeight = intRecordHeight
  271.     End Function
  272.  
  273.     Function SafeDBNull(ByVal Value As Object) As String
  274.         If IsDBNull(Value) Then
  275.             Return String.Empty
  276.         Else
  277.             Return CType(Value, String)
  278.         End If
  279.     End Function
  280.  
  281.     Private Function GetOpenDBConn() As OleDbConnection
  282.         'Creates and opens a database connection
  283.         Dim sConnStr As String = EW_DB_CONNECTION_STRING
  284.         Dim objConnection As New OleDbConnection(sConnStr)
  285.         objConnection.Open()
  286.         Return objConnection
  287.     End Function
  288.  
  289.     Private Function GetData(ByVal connection As OleDbConnection) As OleDbDataReader
  290.         'Creates a DataReader for the report
  291.         Dim strSQL As String, tmpAFlag As String
  292.         Dim objCommand As OleDbCommand = connection.CreateCommand()
  293.  
  294.         tmpAFlag = "N"
  295.         strSQL = "SELECT tblLPR.*, tblEmployees.empName, tblLPRStatus.lstDescription, tblLocations.locDescription, tblLPRFixtureType.ftyDescription, tblLPRFixtureLocation.floDescription FROM tblLPRFixtureLocation RIGHT JOIN (tblLPRFixtureType RIGHT JOIN (tblLocations RIGHT JOIN (tblEmployees RIGHT JOIN (tblLPRStatus RIGHT JOIN tblLPR ON tblLPRStatus.lstID = tblLPR.lprSTID) ON tblEmployees.empID = tblLPR.lprEmpID) ON tblLocations.locID = tblLPR.lprLocationID) ON tblLPRFixtureType.ftyID = tblLPR.lprFixtureTypeID) ON tblLPRFixtureLocation.floID = tblLPR.lprFixtureLocationID"
  296.         If Not IsDBNull(tmpEmployeeID) Or Not IsDBNull(tmpStartDate) Or Not IsDBNull(tmpEndDate) Or Not IsDBNull(tmpLocationID) Or Not IsDBNull(tmpStatusID) Then strSQL = strSQL & " WHERE "
  297.         If Not IsDBNull(tmpStartDate) Or Not IsDBNull(tmpEndDate) Then
  298.             If tmpAFlag = "Y" Then strSQL = strSQL & " AND "
  299.             If Not IsDBNull(tmpStartDate) And tmpStartDate <> "" Then
  300.                 strSQL = strSQL & "(lprDate >= #" & tmpStartDate & "#) "
  301.             End If
  302.             If Not IsDBNull(tmpEndDate) And tmpEndDate <> "" Then
  303.                 If Not IsDBNull(tmpStartDate) And tmpStartDate <> "" Then
  304.                     strSQL = strSQL & " AND "
  305.                 End If
  306.                 strSQL = strSQL & "(lprDate <= #" & tmpEndDate & "#) "
  307.             End If
  308.             tmpAFlag = "Y"
  309.         End If
  310.         If Not IsDBNull(tmpEmployeeID) And tmpEmployeeID <> 0 Then
  311.             If tmpAFlag = "Y" Then strSQL = strSQL & " AND "
  312.             strSQL = strSQL & "(tblLPR.lprEmpID = " & tmpEmployeeID & ") "
  313.             tmpAFlag = "Y"
  314.         End If
  315.         If Not IsDBNull(tmpLocationID) And tmpLocationID <> 0 Then
  316.             If tmpAFlag = "Y" Then strSQL = strSQL & " AND "
  317.             strSQL = strSQL & "(tblLPR.lprLocationID = " & tmpLocationID & ") "
  318.             tmpAFlag = "Y"
  319.         End If
  320.         If Not IsDBNull(tmpStatusID) And tmpStatusID <> 0 Then
  321.             If tmpAFlag = "Y" Then strSQL = strSQL & " AND "
  322.             strSQL = strSQL & "(tblLPR.lprSTID = " & tmpStatusID & ") "
  323.             tmpAFlag = "Y"
  324.         End If
  325.  
  326.         strSQL = strSQL & "ORDER BY lprPriority DESC, tblLPRFixtureLocation.floDescription, tblLPRFixtureType.ftyDescription, tblLPR.lprFixtureNumber, lprDate DESC"
  327.         Session("strSQL") = strSQL
  328.  
  329.  
  330.         objCommand.CommandText = strSQL
  331.         Dim objDataReader As OleDbDataReader = objCommand.ExecuteReader()
  332.  
  333.         Return objDataReader
  334.     End Function
  335.  
  336.     Sub PrintTotals(ByVal document)
  337.         m_fltCurrentY = m_fltCurrentY + 9
  338.         'Adds a new page if the record will not fit on the current page
  339.         '664 is the lowest point on the page that records should appear at
  340.         If 664 - m_fltCurrentY < (intReqHeight * 4) Then AddNewPage(Document)
  341.  
  342.         m_objCurrentPage.Elements.Add(New TextArea(FormatNumber(tmpCount, 0, -2, -2, -2) & " Record(s)", 100, m_fltCurrentY, 650, intReqHeight, Font.TimesRoman, 10))
  343.     End Sub
  344. End Class
  345.