Imports CAMS_ADMIN
Imports CAMS_BL
Imports System.Data
Imports System.Text

Public Class frmPrintAllCases
    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 lblPrintDate As System.Web.UI.WebControls.Label
    Protected WithEvents lblUser As System.Web.UI.WebControls.Label
    Protected WithEvents dgResults As System.Web.UI.WebControls.DataGrid
    Protected WithEvents lblStatusText As System.Web.UI.WebControls.Label
    Protected WithEvents lblStatus As System.Web.UI.WebControls.Label
    Protected WithEvents lblCaseID As System.Web.UI.WebControls.Label
    Protected WithEvents lblRefNumLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblRefNumText As System.Web.UI.WebControls.Label
    Protected WithEvents lblGTLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblGTText As System.Web.UI.WebControls.Label
    Protected WithEvents lblSurname As System.Web.UI.WebControls.Label
    Protected WithEvents lblAddress As System.Web.UI.WebControls.Label
    Protected WithEvents lblPostcode As System.Web.UI.WebControls.Label
    Protected WithEvents lblGO As System.Web.UI.WebControls.Label
    Protected WithEvents lblStage As System.Web.UI.WebControls.Label
    Protected WithEvents lblHA As System.Web.UI.WebControls.Label
    Protected WithEvents lblTALabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblContractorLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblParameters As System.Web.UI.WebControls.Label
    Protected WithEvents lblSurnameLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblAddressLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblPostcodeLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblStatusLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblGOLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblStageLabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblHALabel As System.Web.UI.WebControls.Label
    Protected WithEvents lblTA As System.Web.UI.WebControls.Label
    Protected WithEvents lblContractor As System.Web.UI.WebControls.Label
    Protected WithEvents lblCaseidLabel As System.Web.UI.WebControls.Label
    Protected WithEvents rowParams1 As System.Web.UI.HtmlControls.HtmlTableRow
    Protected WithEvents rowParams2 As System.Web.UI.HtmlControls.HtmlTableRow
    Protected WithEvents rowParams3 As System.Web.UI.HtmlControls.HtmlTableRow
    Protected WithEvents rowParams4 As System.Web.UI.HtmlControls.HtmlTableRow
    Protected WithEvents rowParams5 As System.Web.UI.HtmlControls.HtmlTableRow

    '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=CaseList.xls")
        Me.EnableViewState = False
    End Sub

    Private Sub HideParameters()
        rowParams1.Visible = False
        rowParams2.Visible = False
        rowParams3.Visible = False
        rowParams4.Visible = False
        rowParams5.Visible = False
        lblParameters.Visible = False
        lblCaseidLabel.Visible = False
        lblCaseID.Visible = False
        lblRefNumLabel.Visible = False
        lblRefNumText.Visible = False
        lblGTLabel.Visible = False
        lblGTText.Visible = False
        lblSurnameLabel.Visible = False
        lblSurname.Visible = False
        lblAddressLabel.Visible = False
        lblAddress.Visible = False
        lblPostcodeLabel.Visible = False
        lblPostcode.Visible = False
        lblStatusLabel.Visible = False
        lblStatusText.Visible = False
        lblGOLabel.Visible = False
        lblGO.Visible = False
        lblStageLabel.Visible = False
        lblStage.Visible = False
        lblHALabel.Visible = False
        lblHA.Visible = False
        lblTALabel.Visible = False
        lblTA.Visible = False
        lblContractorLabel.Visible = False
        lblContractor.Visible = False
    End Sub

    Private Sub FillParametersLabels(ByVal oParams As AllCasesParameters)

        If Not oParams Is Nothing Then

            With oParams
                lblCaseID.Text = .CaseId
                If .SimRefNum = "Y" Then
                    lblRefNumLabel.Text = "Sim. Ref. Num"
                Else
                    lblRefNumLabel.Text = "Ref. Num"
                End If

                lblRefNumText.Text = .RefNum

                If .SimGT = "Y" Then
                    lblGTLabel.Text = "Sim. Grant Type"
                Else
                    lblGTLabel.Text = "Grant Type"
                End If

                lblGTText.Text = .GTLabel
                lblSurname.Text = .Surname
                lblAddress.Text = .Address
                lblPostcode.Text = .Postcode
                lblStatusText.Text = .StatusLabel
                lblGO.Text = .GOLabel
                lblStage.Text = .StageLabel
                lblHA.Text = .HALabel
                lblTA.Text = .TALabel
                lblContractor.Text = .ContractorLabel
            End With
        End If

    End Sub

    Private Sub FillReport()
        Dim oCC_Case As New CC_Case
        Dim dsResults As DataSet
        Dim oUser As EC_User = Me.GetUserFromSession
        Dim oParams As AllCasesParameters = CType(Session("AllCasesParams"), AllCasesParameters)

        If Not oUser Is Nothing Then
            lblUser.Text = oUser.Name & " " & oUser.Surname
        End If

        lblPrintDate.Text = Now.ToString(strDateFormat)

        If Not Request.QueryString("filters") Is Nothing Then
            If Request.QueryString("filters").Equals("no") Then
                HideParameters()
            Else
                FillParametersLabels(oParams)
            End If
        Else
            FillParametersLabels(oParams)
        End If

        If Not oParams Is Nothing Then

            If oParams.Status = Constants.CONST_CASESTATUS_NORMAL Then
                lblStatus.Text = "Normal"
            ElseIf oParams.Status = Constants.CONST_CASESTATUS_ATTENTION Then
                lblStatus.Text = "Attention"
            ElseIf oParams.Status = Constants.CONST_CASESTATUS_IMMATTENTION Then
                lblStatus.Text = "Immediate Attention"
            Else
                lblStatus.Text = "All"
            End If

            Try
                With oParams
                    dsResults = oCC_Case.GetCases(0, 0, .IsFromMyCases, .CaseId, .RefNum, .SimRefNum, .GT, .SimGT, _
                                                                .Surname, .Address, .Postcode, .Status, .GO, .Stage, .HA, .TA, .Contractor)
                End With
            Catch ex As Exception
                dsResults = Nothing
            Finally
                dgResults.DataSource = dsResults
                dgResults.DataBind()
            End Try

        End If

    End Sub

    Private Sub dgResults_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgResults.ItemDataBound
        If e.Item.ItemType <> ListItemType.Header Then
            Dim drv As DataRowView = e.Item.DataItem

            If Not drv Is Nothing Then
                e.Item.Cells(0).Text = "&nbsp;" & drv("CASEID")
            End If

        End If

    End Sub

End Class
