Imports DevExpress.Web
Imports System.Collections.Generic
Imports System.Web.UI

Public Class ucAreasEvaluacion
    Inherits System.Web.UI.UserControl


    Public ReadOnly Property GetGridEtapa As ASPxGridView
        Get
            Return GridEtapa
        End Get
    End Property
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    'Protected Sub gridEtapa_BeforePerformDataSelect(sender As Object, e As EventArgs)
    '    Session("idProceso") = CType(sender, ASPxGridView).GetMasterRowKeyValue()

    'End Sub

    Protected Sub gridEtapa_DataBound(sender As Object, e As EventArgs) Handles gridEtapa.DataBound
        CType(sender, ASPxGridView).DetailRows.ExpandAllRows()
    End Sub

    Protected Sub gridFactorPuntaje_BeforePerformDataSelect(sender As Object, e As EventArgs)
        Session("idEtapa") = CType(sender, ASPxGridView).GetMasterRowKeyValue()
    End Sub

    Protected Sub gridArea_BeforePerformDataSelect(sender As Object, e As EventArgs)
        Session("idFactorPuntaje") = CType(sender, ASPxGridView).GetMasterRowKeyValue()
    End Sub


    Protected Sub gridFactorPuntaje_DataBound1(sender As Object, e As EventArgs)
        CType(sender, ASPxGridView).DetailRows.ExpandAllRows()
    End Sub

    Protected Sub gridArea_RowInserting(sender As Object, e As Data.ASPxDataInsertingEventArgs)
        Session("idFactorPuntaje") = CType(sender, ASPxGridView).GetMasterRowKeyValue()
    End Sub

    Protected Sub gridArea_RowUpdating(sender As Object, e As Data.ASPxDataUpdatingEventArgs)
        Session("idFactorPuntaje") = CType(sender, ASPxGridView).GetMasterRowKeyValue()
    End Sub

    Protected Sub gridArea_RowDeleting(sender As Object, e As Data.ASPxDataDeletingEventArgs)
        Session("idFactorPuntaje") = CType(sender, ASPxGridView).GetMasterRowKeyValue()
    End Sub

    Protected Sub gridFactorPuntaje_RowValidating(sender As Object, e As Data.ASPxDataValidationEventArgs)

        If CInt(e.NewValues("FactorPuntajeMaximo")) < CInt(e.NewValues("FactorPuntajeMinimo")) Then
            AddError(e.Errors, CType(sender, ASPxGridView).Columns("FactorPuntajeMinimo"), _
        "El puntaje mínimo no puede ser mayor al puntaje máximo.")
        End If
    End Sub

    Private Sub AddError(ByVal errors As  _
    Dictionary(Of GridViewColumn, String), ByVal column As GridViewColumn, _
    ByVal errorText As String)
        If Not errors.ContainsKey(column) Then
            errors(column) = errorText
        End If
    End Sub

    Protected Sub gridFactorPuntaje_StartRowEditing(sender As Object, e As Data.ASPxStartRowEditingEventArgs)

        If (Not CType(sender, ASPxGridView).IsNewRowEditing) Then
            CType(sender, ASPxGridView).DoRowValidation()
        End If
    End Sub

    Protected Sub gridFactorPuntaje_HtmlRowPrepared(sender As Object, e As ASPxGridViewTableRowEventArgs)
        Dim hasError As Boolean = CInt(e.GetValue("FactorPuntajeMinimo")) > CInt(e.GetValue("FactorPuntajeMaximo"))
        ' If the row has the error(s), its text color is set to red.
        If hasError Then
            e.Row.ForeColor = System.Drawing.Color.Red
        End If
    End Sub
End Class