Imports bdGrupoSanchoToro.db Imports System.Data.Entity Imports DevExpress.Xpf.Core Imports tsWPFCore Imports System.Collections Imports DevExpress.Xpf.Bars Imports System.Threading.Tasks Imports System.Linq.Dynamic Imports bdGrupoSanchoToro.db.Utilidades Imports bdGrupoSanchoToro.db.tscGrupoSanchoToro Public Class ucCorreos Private bd As tscGrupoSanchoToro 'Public Sub New(ListadoFiltrado As List(Of v_albaranesextendido), TextoBusqueda As String, TituloCamposBusqueda As String, CamposBusquedaAlfabeticos() As String, CamposBusquedaNumericos() As String) ' InitializeComponent() ' _ListadoFiltrado = ListadoFiltrado ' Me.BusquedaRapida.Visibility = Visibility.Visible ' 'Me.FiltrosAvanzados.Visibility = Visibility.Collapsed ' Me.teBusqueda.Text = TextoBusqueda ' Me.tbCamposBusqueda.Text = TituloCamposBusqueda ' _CamposBusquedaAlfabeticos = CamposBusquedaAlfabeticos ' _CamposBusquedaNumericos = CamposBusquedaNumericos ' _TextoBusqueda = TextoBusqueda 'End Sub Public Sub New() ' Esta llamada es exigida por el diseñador. InitializeComponent() ' Me.BusquedaRapida.Visibility = Visibility.Collapsed ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Public Overrides Sub Cargado() ContenedorAplicacion.btGuardar.IsVisible = False ContenedorAplicacion.siEstado.IsVisible = False GridBusqueda = Me.gcCorreos 'Dim Hoy = Date.Today 'teFechaFin.EditValue = Hoy 'teFechaInicio.EditValue = New Date(Hoy.Year, 1, 1) End Sub Public Overrides Function EstablecedcPrincipal(Optional Background As Boolean = False, Optional FuerzaNuevo As Boolean = False, Optional Refrescar As Boolean = False) As tsUtilidades.EstadosAplicacion Try If Background OrElse Refrescar Then ObtieneCorreosAsync(bd, Background) Return tsUtilidades.EstadosAplicacion.AplicacionSinIndice Catch ex As Exception Throw New Exception(ex.Message, ex) End Try End Function Public Overrides Sub EstableceDataContextSecundarios(Optional Background As Boolean = False) End Sub Public Overrides Sub EstableceTitulo() Me.docpanel.Caption = "Correos" End Sub Public Overrides ReadOnly Property idRegistroAplicacionActual As String Get Return "Correos" End Get End Property Public Overrides ReadOnly Property NombreTablaBase As String Get Return "correos" End Get End Property Public Overrides ReadOnly Property DescripcionRegistro As String Get Return "correos" End Get End Property Public Overrides Function ObtieneBD() As tsUtilidades.ItsContexto bd = tscGrupoSanchoToro.NuevoContexto() Return bd End Function Public Overrides Function ObtienePermisos() As tsUtilidades.Permisos Return Comun.ObtienePermisos(Me.bd, "AP.ADMINISTRATIVOS", idUsuario) End Function Private Sub ap_Enlazar(Celda As DevExpress.Xpf.Grid.EditGridCellData, Defecto As Boolean) Handles Me.Enlazar Dim ra = DirectCast(Me.gcCorreos.CurrentItem, correos) Select Case Celda.Column.FieldName.ToLower Case "ficheroadjunto" Dim co As correos = gcCorreos.CurrentItem Dim b() = co.idFicheroAdjuntoNavigation.Fichero Dim nf = tsUtilidades.Utilidades.ObtieneFicheroAleatorio(IO.Path.GetExtension(co.idFicheroAdjuntoNavigation.NombreFichero)) IO.File.WriteAllBytes(nf, b) tsUtilidades.Sistema.EjecutaFichero(nf) End Select End Sub Public Function ObtieneCorreos(ByRef DataContext As Object, TextoBusqueda As String, FechaInicio As Date?, FechaFin As Date?) As List(Of correos) Dim rs As IQueryable(Of correos) Dim la As New List(Of correos) Dim iNumExc As Integer = 0 Do Try If TextoBusqueda <> "" Then Dim parametros(0) As Object Dim CamposBusquedaAlfabeticos() As String = {"Destinatario", "Asunto", "Cuerpo"} Dim ExpresionBusqueda = tsWPFCore.Utilidades.Varias.GeneraExpresionBusqueda(TextoBusqueda, Nothing, CamposBusquedaAlfabeticos, Nothing) rs = bd.correos.Where(ExpresionBusqueda) Else rs = bd.correos.AsQueryable End If If FechaInicio.HasValue Then rs = rs.Where(Function(x) x.FechaCreacion >= FechaInicio.Value) End If If FechaFin.HasValue Then FechaFin = FechaFin.Value.AddDays(1) rs = rs.Where(Function(x) x.FechaCreacion < FechaFin.Value) End If la = rs.Include(Function(x) x.idUsuarioNavigation).OrderByDescending(Function(x) x.FechaCreacion).ToList Exit Do Catch ex As Exception iNumExc += 1 If iNumExc > 3 Then rs = Nothing Exit Do End If End Try Loop Return la End Function Public Async Sub ObtieneCorreosAsync(bd As tscGrupoSanchoToro, Background As Boolean) Try Dim rs As New List(Of correos) Dim Busqueda = tsEFCore8.Extensiones.ObjetoNothingAVacio(Me.teBusqueda.EditValue) Dim fi As Date? = teFechaInicio.EditValue Dim ff As Date? = teFechaFin.EditValue If Background Then Me.ContenedorAplicacion.IsEnabled = False Await Task.Run(Sub() rs = ObtieneCorreos(bd, Busqueda, fi, ff) End Sub) Else If DXSplashScreen.IsActive = False Then DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)() DXSplashScreen.SetState("Buscando Correos ...") rs = ObtieneCorreos(bd, Busqueda, fi, ff) End If gcCorreos.ItemsSource = rs DataContext = rs Catch ex As Exception If DXSplashScreen.IsActive Then DXSplashScreen.Close() DXMessageBox.Show(ex.Message, "Error") Finally Me.ContenedorAplicacion.IsEnabled = True If DXSplashScreen.IsActive Then DXSplashScreen.Close() End Try End Sub Private Sub BtBuscar_Click(sender As Object, e As RoutedEventArgs) ObtieneCorreosAsync(bd, False) End Sub Private Sub ucalbaranes_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded teBusqueda.SelectAll() End Sub Private Sub cbIncluirTodos_Checked(sender As Object, e As RoutedEventArgs) Dim Hoy = Date.Today If teFechaFin.EditValue Is Nothing Then teFechaFin.EditValue = Hoy If teFechaInicio.EditValue Is Nothing Then teFechaInicio.EditValue = New Date(Hoy.Year, 1, 1) End Sub 'Private Sub ap_ImprimirPlantilla(sender As Object, e As ItemClickEventArgs, idPlantilla As Integer) Handles ImprimirPlantilla ' Dim ds As List(Of albaranes) ' Dim pl As plantillas = (From p In bd.plantillas Where p.idPlantilla = idPlantilla).First ' Dim sTipo As String = pl.enumeraciones.Codigo ' Dim al As albaranes = Me.DataContext ' ds = New List(Of albaranes) ' ds.Add(al) ' Select Case sTipo ' Case "GRUPLA.AV-ALBARANES" ' Informes.ImprimirPlantilla(bd, idPlantilla, ds, False) ' End Select 'End Sub End Class