Imports CAMS_ADMIN
Imports CAMS_REPORTS
Public Class frmPrintContractorWorkload
    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 dgContractors As System.Web.UI.WebControls.DataGrid
    Protected WithEvents lblTotSL21 As System.Web.UI.WebControls.Label
    Protected WithEvents tblTotOs As System.Web.UI.WebControls.Label

    '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
        Dim oUser As EC_User = Me.GetUserFromSession
        Dim strYearIni As String = "", strYearEnd As String = "", strQuarter As String = ""
        Dim strDateIni, strDateEnd As String

        If Not oUser Is Nothing Then
            lblUser.Text = oUser.Name & " " & oUser.Surname
        End If
        lblPrintDate.Text = Now.ToString(strDateFormat)
        FillReport()
        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = ""
        Response.AppendHeader("content-disposition", "attachment; filename=ContractorWorkload.xls")
        Me.EnableViewState = False
    End Sub

    Private Sub FillReport()
        Dim oCC_Contractor As New CC_ContractorWork
        Dim dsResults As DataSet
        Try
            dsResults = oCC_Contractor.GetContractorWorkLoad
        Catch exc As Exception
            dsResults = Nothing
        Finally
            Me.dgContractors.DataSource = dsResults
            dgContractors.DataBind()
            Me.lblTotSL21.Text = dsResults.Tables(1).Rows(0)("TOTSL21").ToString
            Me.tblTotOs.Text = dsResults.Tables(1).Rows(0)("TOTOS").ToString
        End Try
    End Sub


    Private Sub dgContractors_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgContractors.ItemDataBound
        Dim drv As DataRowView = e.Item.DataItem
        If e.Item.ItemType <> ListItemType.Header Then
            If Not drv Is Nothing Then
                e.Item.Cells(3).Text = Format(drv("TOTAL"), "#,###.00") & "%"
            End If
        End If
    End Sub
End Class
