Imports System.ComponentModel

Public Class OrdenMostrarNota
  Implements ICommand
  Private alumno As Alumno
  Private asignatura As Asignatura
  Private idMin As Integer, idMax As Integer

  Public Sub New(alum As Alumno, asig As Asignatura, min As Integer, max As Integer)
    idMin = min
    idMax = max
    Me.alumno = alum
    AddHandler Me.alumno.PropertyChanged, AddressOf OnPropertyChanged
    Me.asignatura = asig
    AddHandler Me.asignatura.PropertyChanged, AddressOf OnPropertyChanged
  End Sub

  Public Function CanExecute(paramIndex As Object) As Boolean Implements ICommand.CanExecute
    If alumno.IdAlumno >= idMin AndAlso alumno.IdAlumno <= idMax Then
      If alumno.ListaAsignaturas.Count <> 0 Then
        If Not String.IsNullOrEmpty(asignatura.NomAsignatura) Then
          Return True
        End If
      End If
    End If
    Return False
  End Function

  Public Sub Execute(paramIndex As Object) Implements ICommand.Execute
    Dim ind As Integer = Convert.ToInt32(paramIndex)
    asignatura.Nota = alumno.ListaAsignaturas(ind).Nota
  End Sub

  Public Event CanExecuteChanged As EventHandler _
    Implements ICommand.CanExecuteChanged

  Private Sub OnPropertyChanged(sender As Object, e As PropertyChangedEventArgs)
    ' Generar evento
    RaiseEvent CanExecuteChanged(Me, EventArgs.Empty)
  End Sub
End Class
