218 lines
11 KiB
VB.net
218 lines
11 KiB
VB.net
Imports DevExpress.Xpf.LayoutControl
|
|
Imports System.Data
|
|
Imports System.Globalization
|
|
Imports System.IO
|
|
Imports System.Reflection
|
|
Imports bdGestionAntifraude.db
|
|
|
|
Namespace Utilidades
|
|
Public Class Varias
|
|
Public Shared Sub EstableceSoloLecturaRecursivo(Objeto As Object, SoloLectura As Boolean)
|
|
For Each hijo In Objeto.Children
|
|
If hijo.GetType Is GetType(Control) Then
|
|
hijo.isEnabled = Not SoloLectura
|
|
ElseIf hijo.GetType Is GetType(LayoutGroup) OrElse hijo.GetType Is GetType(Grid) Then
|
|
EstableceSoloLecturaRecursivo(hijo, SoloLectura)
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
Public Shared Function ByteArraytoBitmapImage(byteArray As [Byte]()) As BitmapImage
|
|
Dim stream As New MemoryStream(byteArray)
|
|
Dim bitmapImage As New BitmapImage()
|
|
bitmapImage.StreamSource = stream
|
|
Return bitmapImage
|
|
End Function
|
|
|
|
Public Shared Function StreamToBitmapImage(st As Stream) As BitmapImage
|
|
Dim bitmapImage As New BitmapImage()
|
|
bitmapImage.StreamSource = st
|
|
Return bitmapImage
|
|
|
|
End Function
|
|
Public Shared Function PrevInstance() As Boolean
|
|
Try
|
|
If UBound(Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
Return False
|
|
End Try
|
|
End Function
|
|
Public Shared Function GeneraExpresionBusqueda(TextoAbuscar As String, CamposBusquedaNumericos() As String, CamposBusquedaAlfabeticos() As String, CamposBusquedaAlfabeticosPorIgualdad() As String, Optional CamposBusquedaAlfabeticosPorComienzo() As String = Nothing, Optional TipoBusqueda As String = "and") As String
|
|
Dim Expresion As String = ""
|
|
Dim Palabras = TextoAbuscar.Trim.Split(" ").Where(Function(x) x.Trim <> "")
|
|
If CamposBusquedaNumericos IsNot Nothing Then
|
|
For Each palabra In Palabras
|
|
Dim Numero = palabra.Replace(",", ".")
|
|
If CamposBusquedaNumericos.Count > 0 AndAlso Double.TryParse(Numero, Nothing) Then
|
|
For Each c In CamposBusquedaNumericos
|
|
Expresion &= " OrElse " & c & "=" & Numero.TrimEnd(".")
|
|
Next
|
|
End If
|
|
Next
|
|
End If
|
|
If CamposBusquedaAlfabeticos IsNot Nothing Then
|
|
For Each c In CamposBusquedaAlfabeticos
|
|
Dim ExpresionParcial As String = ""
|
|
For Each palabra In Palabras
|
|
palabra = palabra.Replace(Chr(34), """" & """")
|
|
ExpresionParcial &= " " & TipoBusqueda & " " & c & ".Contains(" & Chr(34) & palabra & Chr(34) & ")"
|
|
Next
|
|
ExpresionParcial = "(" & ExpresionParcial.Substring(2 + TipoBusqueda.Length) & ")"
|
|
Expresion &= " OrElse " & ExpresionParcial
|
|
Next
|
|
End If
|
|
|
|
If CamposBusquedaAlfabeticosPorIgualdad IsNot Nothing Then
|
|
Dim ExpresionParcial As String = ""
|
|
For Each palabra In Palabras
|
|
If CamposBusquedaAlfabeticosPorIgualdad.Count > 0 Then
|
|
For Each c In CamposBusquedaAlfabeticosPorIgualdad
|
|
ExpresionParcial &= " OrElse " & c & "=" & Chr(34) & palabra & Chr(34)
|
|
Next
|
|
End If
|
|
Next
|
|
ExpresionParcial = "(" & ExpresionParcial.Substring(4) & ")"
|
|
Expresion &= " OrElse " & ExpresionParcial
|
|
End If
|
|
If CamposBusquedaAlfabeticosPorComienzo IsNot Nothing Then
|
|
Dim ExpresionParcial As String = ""
|
|
For Each palabra In Palabras
|
|
If CamposBusquedaAlfabeticosPorComienzo.Count > 0 Then
|
|
For Each c In CamposBusquedaAlfabeticosPorComienzo
|
|
ExpresionParcial &= " " & TipoBusqueda & " " & c & ".StartsWith(" & Chr(34) & palabra & Chr(34) & ")"
|
|
Next
|
|
End If
|
|
Next
|
|
ExpresionParcial = "(" & ExpresionParcial.Substring(1 + TipoBusqueda.Length) & ")"
|
|
Expresion &= " OrElse " & ExpresionParcial
|
|
End If
|
|
If Expresion <> "" Then
|
|
Return Expresion.Substring(8)
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Function
|
|
|
|
|
|
Public Shared Function GeneraExpresionBusqueda(TextoAbuscar As String, CamposBusquedaIntegers() As String, CamposBusquedaDoubles() As String, CamposBusquedaAlfabeticos() As String, CamposBusquedaAlfabeticosPorIgualdad() As String, ByRef Parametros() As Object, Optional CamposBusquedaAlfabeticosPorComienzo() As String = Nothing, Optional TipoBusqueda As String = "and") As String
|
|
Dim Expresion As String = ""
|
|
Dim Palabras = TextoAbuscar.Trim.Split(" ").Where(Function(x) x.Trim <> "")
|
|
Dim ContNum As Integer = 0
|
|
If CamposBusquedaIntegers IsNot Nothing Then
|
|
For Each palabra In Palabras
|
|
Dim Numero = palabra.Replace(",", ".")
|
|
If Numero.Contains(".") = False AndAlso CamposBusquedaIntegers.Count > 0 AndAlso Integer.TryParse(Numero, Nothing) Then
|
|
For Each c In CamposBusquedaIntegers
|
|
Expresion &= " orelse " & c & "=@" & ContNum.ToString
|
|
ReDim Preserve Parametros(ContNum)
|
|
Parametros(ContNum) = Integer.Parse(Numero, CultureInfo.InvariantCulture)
|
|
ContNum += 1
|
|
Next
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
If CamposBusquedaDoubles IsNot Nothing Then
|
|
For Each palabra In Palabras
|
|
Dim Numero = palabra.Replace(",", ".")
|
|
If CamposBusquedaDoubles.Count > 0 AndAlso Double.TryParse(Numero, Nothing) Then
|
|
For Each c In CamposBusquedaDoubles
|
|
Expresion &= " orelse " & c & "=@" & ContNum.ToString
|
|
ReDim Preserve Parametros(ContNum)
|
|
Parametros(ContNum) = Double.Parse(Numero, CultureInfo.InvariantCulture)
|
|
ContNum += 1
|
|
Next
|
|
End If
|
|
Next
|
|
End If
|
|
If CamposBusquedaAlfabeticos IsNot Nothing Then
|
|
For Each c In CamposBusquedaAlfabeticos
|
|
Dim ExpresionParcial As String = ""
|
|
For Each palabra In Palabras
|
|
palabra = palabra.Replace(Chr(34), "")
|
|
ExpresionParcial &= " " & TipoBusqueda & " " & c & ".Contains(" & "@" & ContNum.ToString & ")"
|
|
ReDim Preserve Parametros(ContNum)
|
|
Parametros(ContNum) = palabra
|
|
ContNum += 1
|
|
Next
|
|
ExpresionParcial = "(" & ExpresionParcial.Substring(2 + TipoBusqueda.Length) & ")"
|
|
Expresion &= " orelse " & ExpresionParcial
|
|
Next
|
|
End If
|
|
|
|
If CamposBusquedaAlfabeticosPorIgualdad IsNot Nothing Then
|
|
Dim ExpresionParcial As String = ""
|
|
For Each palabra In Palabras
|
|
If CamposBusquedaAlfabeticosPorIgualdad.Count > 0 Then
|
|
For Each c In CamposBusquedaAlfabeticosPorIgualdad
|
|
ExpresionParcial &= " orelse " & c & "=" & "@" & ContNum.ToString
|
|
ReDim Preserve Parametros(ContNum)
|
|
Parametros(ContNum) = palabra
|
|
ContNum += 1
|
|
Next
|
|
End If
|
|
Next
|
|
ExpresionParcial = "(" & ExpresionParcial.Substring(4) & ")"
|
|
Expresion &= " orelse " & ExpresionParcial
|
|
End If
|
|
If CamposBusquedaAlfabeticosPorComienzo IsNot Nothing Then
|
|
Dim ExpresionParcial As String = ""
|
|
For Each palabra In Palabras
|
|
If CamposBusquedaAlfabeticosPorComienzo.Count > 0 Then
|
|
For Each c In CamposBusquedaAlfabeticosPorComienzo
|
|
ExpresionParcial &= " " & TipoBusqueda & " " & c & ".StartsWith(" & "@" & ContNum.ToString & ")"
|
|
ReDim Preserve Parametros(ContNum)
|
|
Parametros(ContNum) = palabra
|
|
ContNum += 1
|
|
Next
|
|
End If
|
|
Next
|
|
ExpresionParcial = "(" & ExpresionParcial.Substring(1 + TipoBusqueda.Length) & ")"
|
|
Expresion &= " orelse " & ExpresionParcial
|
|
End If
|
|
If Expresion <> "" Then
|
|
Return Expresion.Substring(8)
|
|
Else
|
|
Return ""
|
|
End If
|
|
End Function
|
|
Public Shared Sub IEnumerableAExcel(Of t)(Datos As IEnumerable(Of t), Fichero As String)
|
|
Dim wb As New ClosedXML.Excel.XLWorkbook
|
|
Dim dt = tsUtilidades.Extensiones.IEnumerableExtensions.CopyToDataTable(Of t)(Datos)
|
|
wb.AddWorksheet(dt)
|
|
wb.SaveAs(Fichero)
|
|
End Sub
|
|
|
|
Public Shared Sub IEnumerableAExcel(Of t)(Datos As List(Of t), Fichero As String)
|
|
Dim wb As New ClosedXML.Excel.XLWorkbook
|
|
Dim dt = tsUtilidades.Extensiones.IEnumerableExtensions.CopyToDataTable(Of t)(Datos)
|
|
wb.AddWorksheet(dt)
|
|
wb.SaveAs(Fichero)
|
|
End Sub
|
|
Public Shared Function IEnumerableAExcel(Of t)(Datos As List(Of t)) As Byte()
|
|
Dim wb As New ClosedXML.Excel.XLWorkbook
|
|
Dim dt = tsUtilidades.Extensiones.IEnumerableExtensions.CopyToDataTable(Of t)(Datos)
|
|
wb.AddWorksheet(dt)
|
|
Dim ms As New MemoryStream
|
|
wb.SaveAs(ms)
|
|
ms.Position = 0
|
|
Return ms.ToArray
|
|
End Function
|
|
Public Shared Function ListaIEnumerableAExcel(Of t)(Datos As List(Of List(Of t)), NombreTablas As List(Of String)) As Byte()
|
|
Dim wb As New ClosedXML.Excel.XLWorkbook
|
|
For i = 0 To Datos.Count - 1
|
|
Dim tabla = Datos(i)
|
|
Dim dt = tsUtilidades.Extensiones.IEnumerableExtensions.CopyToDataTable(Of t)(tabla)
|
|
wb.AddWorksheet(dt, NombreTablas(i))
|
|
Next
|
|
Dim ms As New MemoryStream
|
|
wb.SaveAs(ms)
|
|
ms.Position = 0
|
|
Return ms.ToArray
|
|
End Function
|
|
End Class
|
|
End Namespace |