Imports CAMS_ADMIN
Imports CAMS_BL
Imports CAMS_REPORTS
Imports System.Data
Imports System.Text

Public Class frmPrintGTByAreas
    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 lblYears As System.Web.UI.WebControls.Label
    Protected WithEvents lblQuarter As System.Web.UI.WebControls.Label
    Protected WithEvents lblUser As System.Web.UI.WebControls.Label
    Protected WithEvents lblPrintDate As System.Web.UI.WebControls.Label
    Protected WithEvents litSummWorkload As System.Web.UI.WebControls.Literal
    Protected WithEvents litGTSL21 As System.Web.UI.WebControls.Literal
    Protected WithEvents litGTOnsite As System.Web.UI.WebControls.Literal
    Protected WithEvents litGTCompOnsite As System.Web.UI.WebControls.Literal

    '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=GTByIAreas.xls")
        Me.EnableViewState = False
    End Sub

    Private Sub FillReport()
        Dim oUser As EC_User = Me.GetUserFromSession
        Dim strYearIni As String = "", strYearEnd As String = "", strQuarter As String = ""
        Dim strFecIni As String, strFecEnd As String

        If Not Request.QueryString("yearini") Is Nothing Then
            strYearIni = Request.QueryString("yearini").Trim
        End If

        If Not Request.QueryString("yearend") Is Nothing Then
            strYearEnd = Request.QueryString("yearend").Trim
        End If

        If Not Request.QueryString("quarter") Is Nothing Then
            strQuarter = Request.QueryString("quarter").Trim
        End If

        If Not oUser Is Nothing Then
            lblUser.Text = oUser.Name & " " & oUser.Surname
        End If

        lblPrintDate.Text = Now.ToString(strDateFormat)
        lblYears.Text = strYearIni & " - " & strYearEnd

        Select Case strQuarter
            Case "Q1"
                lblQuarter.Text = "Quarter 1: April " & strYearIni.Substring(2) & " - " & " June " & strYearIni.Substring(2)
                strFecIni = "01/04/" & strYearIni
                strFecEnd = "30/06/" & strYearIni
            Case "Q2"
                lblQuarter.Text = "Quarter 2: July " & strYearIni.Substring(2) & " - " & " September " & strYearIni.Substring(2)
                strFecIni = "01/07/" & strYearIni
                strFecEnd = "30/09/" & strYearIni
            Case "Q3"
                lblQuarter.Text = "Quarter 3: October " & strYearIni.Substring(2) & " - " & " December " & strYearIni.Substring(2)
                strFecIni = "01/10/" & strYearIni
                strFecEnd = "31/12/" & strYearIni
            Case "Q4"
                lblQuarter.Text = "Quarter 4: January " & strYearEnd.Substring(2) & " - " & " March " & strYearEnd.Substring(2)
                strFecIni = "01/01/" & strYearEnd
                strFecEnd = "31/03/" & strYearEnd
            Case "All"
                lblQuarter.Text = "All Quarters: April " & strYearIni.Substring(2) & " - " & " March " & strYearEnd.Substring(2)
                strFecIni = "01/04/" & strYearIni
                strFecEnd = "31/03/" & strYearEnd
        End Select

        DisplaySummWorkload()
        DisplayGTonSL21(strFecIni, strFecEnd)
        DisplayGTonSite(strFecIni, strFecEnd)
        DisplayGTCompOnSite(strFecIni, strFecEnd)
    End Sub

    Private Sub DisplaySummWorkload()
        Dim dsResult As DataSet
        Dim oCC_GtByIndAreas As New CC_GTByIndAreas
        Dim sbText As New StringBuilder

        Try
            dsResult = oCC_GtByIndAreas.PrepareTableSummWorkLoad("", "")

            'litSummWorkload
            If Not dsResult Is Nothing Then

                sbText.Append("<table border=0 cellpadding=2 cellspacing=1 style=""BORDER-COLLAPSE: collapse"">")

                For i As Integer = 0 To dsResult.Tables(0).Rows.Count - 1
                    sbText.Append("<tr class=""PRINT_GRID_ITEM"">")
                    For j As Integer = 0 To dsResult.Tables(0).Columns.Count - 1
                        sbText.Append("<td class=""CELL_BORDER_ALL"" align=center>")
                        sbText.Append("<span class=""PAGE_CONTROL_TEXT"">")
                        sbText.Append(dsResult.Tables(0).Rows(i)(j))
                        sbText.Append("</span>")
                        sbText.Append("</td>")
                    Next
                    sbText.Append("</tr>")
                Next

                sbText.Append("</table>")

                litSummWorkload.Text = sbText.ToString
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub DisplayGTonSL21(ByVal strFecIni As String, ByVal strFecEnd As String)
        Dim dsResult As DataSet
        Dim oCC_GtByIndAreas As New CC_GTByIndAreas
        Dim sbText As New StringBuilder

        Try
            dsResult = oCC_GtByIndAreas.PrepareTableGTonSL21(strFecIni, strFecEnd)

            'litSummWorkload
            If Not dsResult Is Nothing Then

                sbText.Append("<table border=0 cellpadding=2 cellspacing=1 style=""BORDER-COLLAPSE: collapse"">")

                For i As Integer = 0 To dsResult.Tables(0).Rows.Count - 1
                    sbText.Append("<tr class=""PRINT_GRID_ITEM"">")
                    For j As Integer = 0 To dsResult.Tables(0).Columns.Count - 1
                        sbText.Append("<td class=""CELL_BORDER_ALL"" align=center>")
                        sbText.Append("<span class=""PAGE_CONTROL_TEXT"">")
                        sbText.Append(dsResult.Tables(0).Rows(i)(j))
                        sbText.Append("</span>")
                        sbText.Append("</td>")
                    Next
                    sbText.Append("</tr>")
                Next

                sbText.Append("</table>")

                litGTSL21.Text = sbText.ToString
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub DisplayGTonSite(ByVal strFecIni As String, ByVal strFecEnd As String)
        Dim dsResult As DataSet
        Dim oCC_GtByIndAreas As New CC_GTByIndAreas
        Dim sbText As New StringBuilder

        Try
            dsResult = oCC_GtByIndAreas.PrepareTableGTonSite(strFecIni, strFecEnd)

            'litSummWorkload
            If Not dsResult Is Nothing Then

                sbText.Append("<table border=0 cellpadding=2 cellspacing=1 style=""BORDER-COLLAPSE: collapse"">")

                For i As Integer = 0 To dsResult.Tables(0).Rows.Count - 1
                    sbText.Append("<tr class=""PRINT_GRID_ITEM"">")
                    For j As Integer = 0 To dsResult.Tables(0).Columns.Count - 1
                        sbText.Append("<td class=""CELL_BORDER_ALL"" align=center>")
                        sbText.Append("<span class=""PAGE_CONTROL_TEXT"">")
                        sbText.Append(dsResult.Tables(0).Rows(i)(j))
                        sbText.Append("</span>")
                        sbText.Append("</td>")
                    Next
                    sbText.Append("</tr>")
                Next

                sbText.Append("</table>")

                litGTOnsite.Text = sbText.ToString
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub DisplayGTCompOnSite(ByVal strFecIni As String, ByVal strFecEnd As String)
        Dim dsResult As DataSet
        Dim oCC_GtByIndAreas As New CC_GTByIndAreas
        Dim sbText As New StringBuilder

        Try
            dsResult = oCC_GtByIndAreas.PrepareTableGTCompOnSite(strFecIni, strFecEnd)

            'litSummWorkload
            If Not dsResult Is Nothing Then

                sbText.Append("<table border=0 cellpadding=2 cellspacing=1 style=""BORDER-COLLAPSE: collapse"">")

                For i As Integer = 0 To dsResult.Tables(0).Rows.Count - 1
                    sbText.Append("<tr class=""PRINT_GRID_ITEM"">")
                    For j As Integer = 0 To dsResult.Tables(0).Columns.Count - 1
                        sbText.Append("<td class=""CELL_BORDER_ALL"" align=center>")
                        sbText.Append("<span class=""PAGE_CONTROL_TEXT"">")
                        sbText.Append(dsResult.Tables(0).Rows(i)(j))
                        sbText.Append("</span>")
                        sbText.Append("</td>")
                    Next
                    sbText.Append("</tr>")
                Next

                sbText.Append("</table>")

                litGTCompOnsite.Text = sbText.ToString
            End If
        Catch ex As Exception

        End Try
    End Sub

End Class
