Imports DevExpress.Web

Public Class ucEvaluarCompetencias
    Inherits ucBase

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Session("plaza") = ""
        End If
        btnReporteCompetencias.ClientSideEvents.Click = String.Format("function(s, e)  {{ window.open('wfReporteEmpleos.aspx?r=competencias&p={0}','_blank'); }}", Session("plaza"))
        SqlConcursoAEvaluar.SelectParameters("idUser").DefaultValue = CInt(Page.User.Identity.Name)
    End Sub

    Protected Sub gridCalificaciones_BeforePerformDataSelect(sender As Object, e As EventArgs)
        Session("idConcursoPostulante") = (TryCast(sender, ASPxGridView)).GetMasterRowKeyValue()
    End Sub

    Protected Sub gridPostulantes_DataBound(sender As Object, e As EventArgs) Handles gridPostulantes.DataBound
        TryCast(sender, ASPxGridView).DetailRows.ExpandAllRows()
    End Sub

    'Protected Sub cbpCalificar_Callback(sender As Object, e As CallbackEventArgsBase) Handles cbpCalificar.Callback
    '    Session("plaza") = cmbConcursoEvaluar.Value

    '    gridPostulantes.DataBind()
    'End Sub

    Protected Sub gridResultados_DataBound(sender As Object, e As EventArgs) Handles gridResultados.DataBound
        Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
        Session("promedio") = grid.GetTotalSummaryValue(grid.TotalSummary("Puntaje"))
    End Sub

    Protected Sub gridResultados_HtmlRowPrepared(sender As Object, e As ASPxGridViewTableRowEventArgs) Handles gridResultados.HtmlRowPrepared
        If e.RowType <> GridViewRowType.Data Then
            Return
        End If


        Dim puntaje As Double = CDbl(e.GetValue("Puntaje"))

        If puntaje > CDec(Session("promedio")) Then
            e.Row.BackColor = System.Drawing.Color.LightGreen
            e.Row.ForeColor = Drawing.Color.Black
        End If

    End Sub

    Protected Sub gridPostulanteIdioma_CustomUnboundColumnData(sender As Object, e As ASPxGridViewColumnDataEventArgs)
        If e.Column.FieldName = "calidad" Then
            e.Value = CInt(e.GetListSourceFieldValue("IDI_Lee")) + CInt(e.GetListSourceFieldValue("IDI_Escribe")) + CInt(e.GetListSourceFieldValue("IDI_Habla"))
        End If
    End Sub

    Protected Sub gridPostulanteIdioma_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False
        End If
    End Sub

    Protected Sub gridPostulanteEspecialidades_BeforePerformDataSelect1(sender As Object, e As EventArgs)
        Session("idConcursoPostulante") = (TryCast(sender, ASPxGridView)).GetMasterRowKeyValue()
    End Sub

    Protected Sub gridPostulanteCapacitaciones_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False

        End If
    End Sub

    Protected Sub gridPostulanteExperiencia_CustomUnboundColumnData(sender As Object, e As ASPxGridViewColumnDataEventArgs)
        If e.Column.FieldName = "tiempo" Then
            Dim inicio As New Date(e.GetListSourceFieldValue("inicioAnio"), e.GetListSourceFieldValue("inicioMes"), 1)
            Dim fin As Date
            If CBool(e.GetListSourceFieldValue("activo")) Then
                fin = Date.Now
            Else
                fin = New Date(e.GetListSourceFieldValue("finAnio"), e.GetListSourceFieldValue("finMes"), 1)
            End If
            Dim anios As Integer = DateDiff(DateInterval.Year, inicio, fin)
            Dim meses As Integer = DateDiff(DateInterval.Month, inicio, fin)
            meses = meses Mod 12

            e.Value = String.Format("{0} año(s), {1} mes(es)", anios, meses)
        End If
    End Sub

    Protected Sub gridPostulanteExperiencia_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False
        End If
    End Sub

    Protected Sub gridReferencias_BeforePerformDataSelect(sender As Object, e As EventArgs)
        Dim grid As ASPxGridView = CType(sender, ASPxGridView)
        Session("idUsuario") = grid.GetMasterRowFieldValues("idUsuario").ToString()
    End Sub

    Protected Sub gridRefLaborales_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False
        End If
    End Sub

    Protected Sub gridReferencias_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False
        End If
    End Sub

    Protected Sub gridDiscapacidad_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False
        End If
    End Sub

    Protected Sub gridPostulanteEspecialidades_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False
        End If
    End Sub



    Protected Sub gridPostulanteConocimientos_DataBound(sender As Object, e As EventArgs)
        Dim g As ASPxGridView = TryCast(sender, ASPxGridView)
        If g.VisibleRowCount = 0 Then
            g.ClientVisible = False
        End If
    End Sub


    Protected Sub cmbConcursoEvaluar_ValueChanged(sender As Object, e As EventArgs) Handles cmbConcursoEvaluar.ValueChanged
        Session("plaza") = cmbConcursoEvaluar.Value
    End Sub

    Protected Sub btnConfigurar_Click(sender As Object, e As EventArgs) Handles btnConfigurar.Click
        If cmbConcursoEvaluar.SelectedIndex <> -1 Then

            Dim msg As New MSG("competencias")
            Dim oPlaza As New PlazaBusinessObject(CInt(cmbConcursoEvaluar.Value))
            oPlaza.Entity.idEstadoPlaza = 5
            msg = oPlaza.SaveChanges()

            CustomMessage(String.Format("Se ha cambiado el estado del Concurso: {0} | {1}, ahora regresara a la pantalla de configuración. Por favor seleccionar este concurso.", oPlaza.Entity.Identificador, oPlaza.Entity.nombrePuesto), "Competencias borradas", , "wfConfiguracionEvaluacion.aspx")
        Else
            CustomMessage("No tiene seleccionado un concurso", "Error")
        End If
    End Sub


    Protected Sub cmbConcursoEvaluar_DataBound(sender As Object, e As EventArgs) Handles cmbConcursoEvaluar.DataBound
        CType(sender, ASPxComboBox).NullText = CType(sender, ASPxComboBox).Items.Count & " concursos disponibles."
    End Sub
End Class