
Imports System.Data.Entity
Imports DevExpress.Xpf.Core.ServerMode
Imports DevExpress.Xpf.Grid
Imports tsWPF
Imports DevExpress.Xpf.Docking
Imports DevExpress.Xpf.Core

Public Class ucListado
    Implements tsWPF.IApLineas

    Private _Titulo As String
    Private _Datos As Object
    Private WithEvents ApLineas As tsWPF.ApLineas

    Public ReadOnly Property Titulo As String Implements tsWPF.IApLineas.Titulo
        Get
            Return _Titulo
        End Get
    End Property


    'Public Sub Editar() Implements tsWPF.IApLineas.Editar
    '    Dim id As Integer = Me.gc.SelectedItems(0).idPersona
    '    Dim ucPersona As New ucPersona
    '    Dim dwi As dxwInicio = Window.GetWindow(Me)
    '    tsWPF.ApCabLin.AbrirUcCL(ucPersona, dwi.grupodoc, ApLineas, ApLineas.dcfg, ApLineas.dcn, ApLineas.dsc, ApLineas.OtrosParametros, id)
    'End Sub


    Public Sub EstableceDataContext(ByRef DataContext As Object, Optional Background As Boolean = False) Implements tsWPF.IApLineas.EstableceDataContext
        Try
            Me.gc.ItemsSource = _Datos
        Catch ex As Exception
            If ex.InnerException IsNot Nothing Then
                DXMessageBox.Show(ex.Message & " " & ex.InnerException.Message, "Error en EstableceDataContext")

            Else
                DXMessageBox.Show(ex.Message, "Error en EstableceDataContext")
            End If
        End Try
    End Sub

    Public ReadOnly Property NombreTablaBase As String Implements tsWPF.IApLineas.NombreTablaBase
        Get
            Return ""
        End Get
    End Property

    Public Sub Nuevo() Implements tsWPF.IApLineas.Nuevo

    End Sub



    Public Sub EstableceApLin(ApLin As tsWPF.ApLineas) Implements tsWPF.IApLineas.EstableceApLin
        Me.ApLineas = ApLin
    End Sub

    Public Function ObtieneContexto(dcn As tsl5.Datos.DatosConexionCliente) As System.Data.Objects.ObjectContext Implements tsWPF.IApLineas.ObtieneContexto
        Return Nothing
    End Function

    Public Function ObtienePermisos() As tsWPF.Permisos Implements tsWPF.IApLineas.ObtienePermisos
        Dim per As New Permisos
        per.Consultar = True
        per.Eliminar = False
        per.Impresion = True
        per.Modificar = False
        per.Nuevos = False
        per.Otros = True
        per.Exportar = True
        Return per
    End Function

    Public Function ObtieneRejilla() As tsWPF.tsGridControl Implements tsWPF.IApLineas.ObtieneRejilla
        Return Me.gc
    End Function

    'Private Sub ApLineas_EjecutarAccion(sender As Object, e As DevExpress.Xpf.Bars.ItemClickEventArgs, idAccion As Integer) Handles ApLineas.EjecutarAccion
    '    Select Case idAccion
    '        Case 1
    '            Dim ucGenerar As New ucGenerarNominas
    '            Dim dwi As dxwInicio = Window.GetWindow(Me)
    '            tsWPF.ApCabLin.AbrirUcCL(ucGenerar, dwi.grupodoc, ApLineas, ApLineas.dcfg, ApLineas.dcn, ApLineas.dsc, ApLineas.OtrosParametros, Nothing)

    '    End Select
    'End Sub
    'Private Sub ApLineas_Enlazar(Celda As EditGridCellData, Defecto As Boolean) Handles ApLineas.Enlazar


    'End Sub

    Public Function ObtieneCampoIndice() As String Implements tsWPF.IApLineas.ObtieneCampoIndice
        Return ""
    End Function
    Public Shared Sub MuestraListado(Listado As Object, Titulo As String, dg As DocumentGroup, dcfg As tsl5.Datos.DatosConfiguracionCliente, dcn As tsl5.Datos.DatosConexionCliente, dsc As tsl5.Datos.DatosSesionCliente, Optional FuncionErrorNoControlado As tsWPF.ApLineas.ErrorNoControlado = Nothing, Optional FuncionCargado As tsWPF.ApLineas.DelegadoCargado = Nothing)
        Dim ucL As New ucListado
        ucL._Titulo = Titulo
        ucL._Datos = Listado
        ApLineas.AbrirUcL(ucL, dg, dcfg, dcn, dsc, "ucListado-" & Now.ToString, , , , FuncionErrorNoControlado, FuncionCargado)
        ucL.tv.BestFitColumns()
    End Sub

    Private Sub gc_Loaded(sender As Object, wpe As RoutedEventArgs) Handles gc.Loaded
        For Each c In gc.Columns
            c.ReadOnly = True
            c.AllowEditing = DevExpress.Utils.DefaultBoolean.False
        Next
    End Sub
End Class
