Imports CAMS_ADMIN
Imports CAMS_BL
Imports CAMS_REPORTS
Imports System.Data
Imports System.Text

Public Class frmPrintContractorWork
    Inherits CAMSBasePage

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblUser As System.Web.UI.WebControls.Label
    Protected WithEvents lblPrintDate As System.Web.UI.WebControls.Label
    Protected WithEvents lblContractor As System.Web.UI.WebControls.Label
    Protected WithEvents rpWorkloadPerStage As System.Web.UI.WebControls.Repeater

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private strDateFormat As String = "dd/MM/yyyy HH:mm"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillReport()
        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = ""
        Response.AppendHeader("content-disposition", "attachment; filename=QuarterlySummaryReport.xls")
        Me.EnableViewState = False
    End Sub

    Private Sub FillReport()
        Dim oUser As EC_User = Me.GetUserFromSession
        Dim oCC_Contractor As New CC_Contractor
        Dim oContractor As EC_Contractor
        Dim strContractorID As String = ""
        Dim oCC_ContractorWork As New CC_ContractorWork
        Dim dsResults As DataSet

        Try
            If Not Request.QueryString("id") Is Nothing Then
                strContractorID = Request.QueryString("id").Trim
            End If

            If Not oUser Is Nothing Then
                lblUser.Text = oUser.Name & " " & oUser.Surname
            End If

            If strContractorID.Trim.Equals(String.Empty) = False Then
                oContractor = oCC_Contractor.GetContractorByID(strContractorID)
                dsResults = oCC_ContractorWork.GetContractorWorkLoadPerStage(strContractorID)
            End If

            If Not oContractor Is Nothing Then
                lblContractor.Text = oContractor.CompanyName
            End If

            lblPrintDate.Text = Now.ToString(strDateFormat)
        Catch ex As Exception
            dsResults = Nothing
        Finally
            rpWorkloadPerStage.DataSource = dsResults
            rpWorkloadPerStage.DataBind()
        End Try

    End Sub

End Class
